#include "modbusfactory.h"

#ifdef XNLINUX
#include <unistd.h>
#include <time.h>
#include<sys/wait.h>
#endif

CModbusFactory::CModbusFactory()
{

}

CModbusFactory::~CModbusFactory()
{

}


// >= 0 OK 
// -1 准备失败 
// -2 最后了 
// -3 参数错误 
int CModbusFactory::prepareDatagram(int iIndexStep, char* pSendDataBuf, uchar uaAddr)
{
	if (iIndexStep < 0 || 0 == pSendDataBuf)
	{
		return -3;
	}

	int iLenVal = 0;	
	memset(pSendDataBuf, 0, SNED_BUFFER_LENGHT);

	switch (iIndexStep)
	{
	case 0: 
		iLenVal = formDatagram(1/*读取告警状态*/, uaAddr, 2, 1, 52, pSendDataBuf);	          // 离散输入寄存器 1 ~ 52	
		break;

	case 1: 
		iLenVal = formDatagram(8/*读取电池1~50 电压*/, uaAddr, 4, 1, 100, pSendDataBuf);	      // 输入寄存器 1 ~ 99
		break;
	case 2: 
		iLenVal = formDatagram(9/*读取电池51~100电压*/, uaAddr, 4, 101, 100, pSendDataBuf);	      // 输入寄存器 101 ~ 199
		break;
	case 3: 
		iLenVal = formDatagram(10/*读取电池101~150电压*/, uaAddr, 4, 201, 100, pSendDataBuf);	  // 输入寄存器 201 ~ 299
		break;
	case 4:  
		iLenVal = formDatagram(11/*读取电池151~200电压*/, uaAddr, 4, 301, 100, pSendDataBuf);	  // 输入寄存器 301 ~ 399
		break;
	case 5:  
		iLenVal = formDatagram(12/*读取电池201~250电压*/, uaAddr, 4, 401, 100, pSendDataBuf);	  // 输入寄存器 401 ~ 499
		break;
	case 6:  
		iLenVal = formDatagram(13/*读取电池251~300电压*/, uaAddr, 4, 501, 100, pSendDataBuf);	  // 输入寄存器 501 ~ 599
		break;
	case 7:  
		iLenVal = formDatagram(14/*读取电池301~350电压*/, uaAddr, 4, 601, 100, pSendDataBuf);	  // 输入寄存器 601 ~ 699
		break;
	case 8: 
		iLenVal = formDatagram(15/*读取电池350~400电压*/, uaAddr, 4, 701, 100, pSendDataBuf);	  // 输入寄存器 701 ~ 799 
		break;

	case 9:  
		iLenVal = formDatagram(16/*读取电池1~50 温度*/, uaAddr, 4, 801, 100, pSendDataBuf);	  // 输入寄存器 801 ~ 899
		break;
	case 10: 
		iLenVal = formDatagram(17/*读取电池51~100温度*/, uaAddr, 4, 901, 100, pSendDataBuf);	  // 输入寄存器 901 ~ 999
		break;
	case 11:  
		iLenVal = formDatagram(18/*读取电池101~150温度*/, uaAddr, 4, 1001, 100, pSendDataBuf);	  // 输入寄存器 1001 ~ 1099
		break;
	case 12:  
		iLenVal = formDatagram(19/*读取电池151~200温度*/, uaAddr, 4, 1101, 100, pSendDataBuf);	  // 输入寄存器 1101 ~ 1199
		break;
	case 13:  
		iLenVal = formDatagram(20/*读取电池201~250温度*/, uaAddr, 4, 1201, 100, pSendDataBuf);	  // 输入寄存器 1201 ~ 1299
		break;
	case 14:  
		iLenVal = formDatagram(21/*读取电池251~300温度*/, uaAddr, 4, 1301, 100, pSendDataBuf);	  // 输入寄存器 1301 ~ 1399
		break;
	case 15:  
		iLenVal = formDatagram(22/*读取电池301~350温度*/, uaAddr, 4, 1401, 100, pSendDataBuf);	  // 输入寄存器 1401 ~ 1499
		break;
	case 16:  
		iLenVal = formDatagram(23/*读取电池350~400温度*/, uaAddr, 4, 1501, 100, pSendDataBuf);	  // 输入寄存器 1501 ~ 1599
		break;

	case 17: 
		iLenVal = formDatagram(24/*读取电池1~50 Soc*/, uaAddr, 4, 1601, 100, pSendDataBuf);	      // 输入寄存器 1601 ~ 1699
		break;
	case 18:  
		iLenVal = formDatagram(25/*读取电池51~100Soc*/, uaAddr, 4, 1701, 100, pSendDataBuf);	  // 输入寄存器 1701 ~ 1799
		break;
	case 19: 
		iLenVal = formDatagram(26/*读取电池101~150Soc*/, uaAddr, 4, 1801, 100, pSendDataBuf);	  // 输入寄存器 1801 ~ 1899
		break;
	case 20:  
		iLenVal = formDatagram(27/*读取电池151~200Soc*/, uaAddr, 4, 1901, 100, pSendDataBuf);	  // 输入寄存器 1901 ~ 1999
		break;
	case 21:  
		iLenVal = formDatagram(28/*读取电池201~250Soc*/, uaAddr, 4, 2001, 100, pSendDataBuf);	  // 输入寄存器 2001 ~ 2099
		break;
	case 22:  
		iLenVal = formDatagram(29/*读取电池251~300Soc*/, uaAddr, 4, 2101, 100, pSendDataBuf);	  // 输入寄存器 2101 ~ 2199
		break;
	case 23:  
		iLenVal = formDatagram(30/*读取电池301~350Soc*/, uaAddr, 4, 2201, 100, pSendDataBuf);	  // 输入寄存器 2201 ~ 2299
		break;
	case 24:  
		iLenVal = formDatagram(31/*读取电池350~400Soc*/, uaAddr, 4, 2301, 100, pSendDataBuf);	  // 输入寄存器 2301 ~ 2399
		break;

	case 25:  
		iLenVal = formDatagram(32/*读取电池1~50 内阻*/, uaAddr, 4, 2401, 100, pSendDataBuf);	  // 输入寄存器 2401 ~ 2499
		break;
	case 26: 
		iLenVal = formDatagram(33/*读取电池51~100内阻*/, uaAddr, 4, 2501, 100, pSendDataBuf);	  // 输入寄存器 2501 ~ 2599
		break;
	case 27:  
		iLenVal = formDatagram(34/*读取电池101~150内阻*/, uaAddr, 4, 2601, 100, pSendDataBuf);	  // 输入寄存器 2601 ~ 2699
		break;
	case 28: 
		iLenVal = formDatagram(35/*读取电池151~200内阻*/, uaAddr, 4, 2701, 100, pSendDataBuf);	  // 输入寄存器 2701 ~ 2799
		break;
	case 29:  
		iLenVal = formDatagram(36/*读取电池201~250内阻*/, uaAddr, 4, 2801, 100, pSendDataBuf);	  // 输入寄存器 2801 ~ 2899
		break;
	case 30:  
		iLenVal = formDatagram(37/*读取电池251~300内阻*/, uaAddr, 4, 2901, 100, pSendDataBuf);	  // 输入寄存器 2901 ~ 2999
		break;
	case 31:  
		iLenVal = formDatagram(38/*读取电池301~350内阻*/, uaAddr, 4, 3001, 100, pSendDataBuf);	  // 输入寄存器 3001 ~ 3099
		break;
	case 32:  
		iLenVal = formDatagram(39/*读取电池350~400内阻*/, uaAddr, 4, 3101, 100, pSendDataBuf);	  // 输入寄存器 3101 ~ 3199
		break;

	case 33: 
		iLenVal = formDatagram(40/*读取电池1~50 Soh*/, uaAddr, 4, 3201, 100, pSendDataBuf);	      // 输入寄存器 3201 ~ 3299
		break;
	case 34:  
		iLenVal = formDatagram(41/*读取电池51~100Soh*/, uaAddr, 4, 3301, 100, pSendDataBuf);	  // 输入寄存器 3301 ~ 3399
		break;
	case 35:  
		iLenVal = formDatagram(42/*读取电池101~150Soh*/, uaAddr, 4, 3401, 100, pSendDataBuf);	  // 输入寄存器 3401 ~ 3499
		break;
	case 36:  
		iLenVal = formDatagram(43/*读取电池151~200Soh*/, uaAddr, 4, 3501, 100, pSendDataBuf);	  // 输入寄存器 3501 ~ 3599
		break;
	case 37:  
		iLenVal = formDatagram(44/*读取电池201~250Soh*/, uaAddr, 4, 3601, 100, pSendDataBuf);	  // 输入寄存器 3601 ~ 3699
		break;
	case 38:  
		iLenVal = formDatagram(45/*读取电池251~300Soh*/, uaAddr, 4, 3701, 100, pSendDataBuf);	  // 输入寄存器 3701 ~ 3799
		break;
	case 39:  
		iLenVal = formDatagram(46/*读取电池301~350Soh*/, uaAddr, 4, 3801, 100, pSendDataBuf);	  // 输入寄存器 3801 ~ 3899
		break;
	case 40:  
		iLenVal = formDatagram(47/*读取电池350~400Soh*/, uaAddr, 4, 3901, 100, pSendDataBuf);	  // 输入寄存器 3901 ~ 3999
		break;
	case 41:  
		iLenVal = formDatagram(48/*读取其他浮点数*/, uaAddr, 4, 4001, 56, pSendDataBuf);	      // 输入寄存器 4001 ~ 4055
		break;
	case 42: 
		iLenVal = formDatagram(49/*读取其他短整形数*/, uaAddr, 4, 5001, 25, pSendDataBuf);	     // 输入寄存器 5001 ~ 5025
		break;

	case 200:
		iLenVal = formDatagram(200, uaAddr, 4, 1, 100, pSendDataBuf);	  // 采集BA中的通用输入寄存器
		break;
	case 201:
		iLenVal = formDatagram(201, uaAddr, 4, 1, 87, pSendDataBuf);	  // 电池堆信息
		break;
	case 202:
		iLenVal = formDatagram(202, uaAddr, 3, 1, 8, pSendDataBuf);	      // 电池堆保持寄存器
		break;
	case 203:
		iLenVal = formDatagram(203, uaAddr, 3, 1, 44, pSendDataBuf);	  // 电池组保持寄存器
		break;

	default:
		iLenVal = -2;
		break;
	}

	return iLenVal;
}

// >= 0 OK 
// -1 准备失败 
// -2 最后了 
// -3 参数错误 
//int CModbusFactory::prepareSetHoldDatagram(int iSetHoldRegStep, CBattStack* pStack, CBattBank* pBattBank, SAlarmParam* pAlarmParam, char* pSendDataBuf)
//{
//	if (iSetHoldRegStep < 0 || 0 == pSendDataBuf)
//	{
//		return -3;
//	}
//
//	// some varibales
//	int iLenVal = 0;
//	quint16 usTemp = 0;
//
//	memset(pSendDataBuf, 0, SNED_BUFFER_LENGHT);
//
//	switch (iSetHoldRegStep) 
//	{
//	case 301:  // 设置电池堆保持寄存器
//		if (pStack)
//		{
//			usTemp = 301;			
//			addParam2Buffer(pSendDataBuf, usTemp);
//			iLenVal += 2;
//
//			iLenVal += 2;        // 协议标识
//
//			usTemp = 9;          // 长度
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = 1;          // Addr
//			iLenVal += 1;
//
//			*(pSendDataBuf + iLenVal) = 16;         // Func Code
//			iLenVal += 1;
//
//			usTemp = 1;                             // Start Reg Addr
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			usTemp = 1;                             // Reg Num
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = 2;          // Byte Num
//			iLenVal += 1;   
//			                         
//			addParam2Buffer(pSendDataBuf + iLenVal, pStack->usDelayBeforeCutCntor);  // Value
//			iLenVal += 2;
//		}
//		else
//		{
//			iLenVal = -3;
//		}
//		break;
//	case 302:  // 设置预警参数
//		if (pBattBank && pAlarmParam)
//		{
//			usTemp = 302;			
//			addParam2Buffer(pSendDataBuf, usTemp);
//			iLenVal += 2;
//
//			iLenVal += 2;        // 协议标识
//
//			usTemp = 31;          // 长度
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = pBattBank->uaModbusAddr;          // Addr
//			iLenVal += 1;
//
//			*(pSendDataBuf + iLenVal) = 16;         // Func Code
//			iLenVal += 1;
//
//			usTemp = 1;                             // Start Reg Addr
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			usTemp = 12;                             // Reg Num
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = 24;          // Byte Num
//			iLenVal += 1;   
//
//			// Value
//			for(usTemp = 1; usTemp <= 12; ++usTemp) // 寄存器
//			{
//				addHoldRegVal2BufferAlarm(pSendDataBuf + iLenVal, usTemp, pAlarmParam, pBattBank);
//				iLenVal += 2;
//			}
//		}
//		else
//		{
//			iLenVal = -3;
//		}
//		break;
//	case 303:  // 设置告警参数
//		if (pBattBank && pAlarmParam)
//		{
//			usTemp = 303;			
//			addParam2Buffer(pSendDataBuf, usTemp);
//			iLenVal += 2;
//
//			iLenVal += 2;        // 协议标识
//
//			usTemp = 31;          // 长度
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = pBattBank->uaModbusAddr;          // Addr
//			iLenVal += 1;
//
//			*(pSendDataBuf + iLenVal) = 16;         // Func Code
//			iLenVal += 1;
//
//			usTemp = 13;                             // Start Reg Addr
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			usTemp = 12;                             // Reg Num
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = 24;          // Byte Num
//			iLenVal += 1;   
//
//			// Value
//			for(usTemp = 13; usTemp <= 24; ++usTemp) // 寄存器
//			{
//				addHoldRegVal2BufferAlarm(pSendDataBuf + iLenVal, usTemp, pAlarmParam, pBattBank);
//				iLenVal += 2;
//			}
//		}
//		else
//		{
//			iLenVal = -3;
//		}
//		break;
//	case 304:  // 设置保护参数
//		if (pBattBank && pAlarmParam)
//		{
//			usTemp = 304;			
//			addParam2Buffer(pSendDataBuf, usTemp);
//			iLenVal += 2;
//
//			iLenVal += 2;        // 协议标识
//
//			usTemp = 31;          // 长度
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = pBattBank->uaModbusAddr;          // Addr
//			iLenVal += 1;
//
//			*(pSendDataBuf + iLenVal) = 16;         // Func Code
//			iLenVal += 1;
//
//			usTemp = 25;                             // Start Reg Addr
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			usTemp = 12;                             // Reg Num
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = 24;          // Byte Num
//			iLenVal += 1;   
//
//			// Value
//			for(usTemp = 25; usTemp <= 36; ++usTemp) // 寄存器
//			{
//				addHoldRegVal2BufferAlarm(pSendDataBuf + iLenVal, usTemp, pAlarmParam, pBattBank);
//				iLenVal += 2;
//			}
//		}
//		else
//		{
//			iLenVal = -3;
//		}
//		break;
//	case 305:  // 设置调整步长
//		if (pBattBank && pAlarmParam)
//		{
//			usTemp = 305;			
//			addParam2Buffer(pSendDataBuf, usTemp);
//			iLenVal += 2;
//
//			iLenVal += 2;        // 协议标识
//
//			usTemp = 23;          // 长度
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = pBattBank->uaModbusAddr;          // Addr
//			iLenVal += 1;
//
//			*(pSendDataBuf + iLenVal) = 16;         // Func Code
//			iLenVal += 1;
//
//			usTemp = 37;                             // Start Reg Addr
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			usTemp = 8;                             // Reg Num
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = 16;          // Byte Num
//			iLenVal += 1;   
//
//			// Value
//			for(usTemp = 37; usTemp <= 44; ++usTemp) // 寄存器
//			{
//				addHoldRegVal2BufferAlarm(pSendDataBuf + iLenVal, usTemp, pAlarmParam, pBattBank);
//				iLenVal += 2;
//			}
//		}
//		else
//		{
//			iLenVal = -3;
//		}
//		break;
//	default:
//		iLenVal = -2;
//		break;
//	}
//
//	return iLenVal;
//}

int CModbusFactory::addParam2Buffer(char* pData, quint32 uiParamVal)
{
	*pData = (char)(uiParamVal >> 24);

	++pData;
	*pData = (char)(uiParamVal >> 16);

	++pData;
	*pData = (char)(uiParamVal >> 8);

	++pData;
	*pData = (char)(uiParamVal);

	return  0;
}

int CModbusFactory::addParam2Buffer(char* pData, quint16 uiParamVal)
{
	*pData = (char)(uiParamVal >> 8);

	++pData;
	*pData = (char)(uiParamVal);

	return  0;
}

int CModbusFactory::addParam2Buffer(char* pData, float fParamVal)
{
	char aTemp[4];
	memcpy(aTemp, (char*)&fParamVal, 4);
	
	*pData = aTemp[3];
	++pData;
	*pData = aTemp[2];
	++pData;
	*pData = aTemp[1];
	++pData;
	*pData = aTemp[0];
	
	return 0;
}

int CModbusFactory::getParamFromBuffer(char* pData, quint16& uiParamVal)
{
	uiParamVal = (unsigned char)*pData;
	uiParamVal = uiParamVal * 256;

	++pData;

	uiParamVal += (unsigned char)*pData;

	return 0;
}

int CModbusFactory::getParamFromBuffer(char* pData, quint32& uiParamVal)
{
	uiParamVal = (unsigned char)*pData;

	uiParamVal = uiParamVal * 256;
	++pData;
	uiParamVal += (unsigned char)*pData;

	uiParamVal = uiParamVal * 256;
	++pData;
	uiParamVal += (unsigned char)*pData;

	uiParamVal = uiParamVal * 256;
	++pData;
	uiParamVal += (unsigned char)*pData;

	return 0;
}


int CModbusFactory::getParamFromBuffer(char* pData, float& fParamVal)
{
	char aTemp[4];
	aTemp[3] = *pData;
	++pData;
	aTemp[2] = *pData;
	++pData;
	aTemp[1] = *pData;
	++pData;
	aTemp[0] = *pData;

	memcpy(&fParamVal, aTemp, 4);
	return 0;
}

int CModbusFactory::formDatagram(quint16 usEvent, uchar uaAddr, uchar uaFuncCode, quint16 usStartReg, quint16 usRegNum, char* pSendDataBuf)
{
	int iLenVal = 0;
	quint16 usTemp = 0;

	addParam2Buffer(pSendDataBuf, usEvent);
	iLenVal += 2;

	iLenVal += 2;        // 协议标识

	usTemp = 6;          // 长度
	addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pSendDataBuf + iLenVal) = uaAddr;
	iLenVal += 1;

	*(pSendDataBuf + iLenVal) = uaFuncCode;
	iLenVal += 1;

	usTemp = usStartReg;
	addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	usTemp = usRegNum;
	addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	return iLenVal;
}

int CModbusFactory::formHoldRegDatagram(quint16 usEvent, uchar uaAddr, quint16 usStartReg, quint16 usRegNum, char* pSendDataBuf, float* pFVal)
{
	// some variables
	int iLenVal = 0;
	quint16 usTemp = 0;

	if (0 != usRegNum % 2)
	{
		--usRegNum; // 变成偶数
	}

	addParam2Buffer(pSendDataBuf, usEvent);
	iLenVal += 2;

	iLenVal += 2;        // 协议标识

	usTemp = usRegNum * 2 + 7;          // 长度
	addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pSendDataBuf + iLenVal) = uaAddr;
	iLenVal += 1;

	*(pSendDataBuf + iLenVal) = 0x10;
	iLenVal += 1;

	usTemp = usStartReg;
	addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	usTemp = usRegNum;
	addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pSendDataBuf + iLenVal) = (quint8)(usRegNum * 2);   // 长度
	iLenVal += 1;

	for(int i = 0; i < usRegNum / 2; ++i)
	{
		addParam2Buffer(pSendDataBuf + iLenVal, *pFVal);
		++pFVal;
		iLenVal += 4;
	}

	return iLenVal;
}

// >= 0 OK 返回值
// -1 参数错误
// -2 长度不正确
// -3 功能码不正确

// < 0 处理失败
int CModbusFactory::analyReqDatagram(char* pDataBuf, int iLen, SMdobusTcpReq& req)
{
	if(0 == pDataBuf || iLen < 12)
	{
		return -1;
	}

	req.usEvent = 0;
	req.usProto = 0;
	req.usLen = 0;
	req.uaAddr = 0;
	req.uaFuncCode = 0;
	req.usRegAddr = 0;
	req.usRegNum = 0;

	// Read Data
	int iInedx = 0;

	getParamFromBuffer(pDataBuf, req.usEvent);
	iInedx += 2;

	getParamFromBuffer(pDataBuf + iInedx, req.usProto);
	iInedx += 2;

	getParamFromBuffer(pDataBuf + iInedx, req.usLen);
	iInedx += 2;

	req.uaAddr = (uchar)*(pDataBuf + iInedx);
	iInedx += 1;

	req.uaFuncCode = (uchar)*(pDataBuf + iInedx);
	iInedx += 1;

	getParamFromBuffer(pDataBuf + iInedx, req.usRegAddr);
	iInedx += 2;

	getParamFromBuffer(pDataBuf + iInedx, req.usRegNum);
	iInedx += 2;

	// 校验报文是否正确
	if(2 == req.uaFuncCode || 4 == req.uaFuncCode || 3 == req.uaFuncCode || 6 == req.uaFuncCode) // 功能码 0x02 0x04 0x03 0x06 
	{
		if (req.usLen != 6)
		{
			return -2;
		}	
	}
	else if(17 == req.uaFuncCode) // 0x11
	{
		if (req.usLen < 6)
		{
			return -2;
		}
	}
	else if(16 == req.uaFuncCode) // 功能码 0x10
	{
		int iByteNum = (uchar)*(pDataBuf + iInedx); // 后续字节数
		iInedx += 1;

		if (req.usRegNum * 2 != iByteNum || req.usLen != req.usRegNum * 2 + 7 || iLen < req.usLen + 6) // iLen >= req.usLen + 6
		{
			return -2;
		}	
	}
	else 
	{
		return -3;
	}

	return 0;
}

// >= 0 OK 
// -1 参数错误 
// -2 功能码错误 
// -3 超出范围
int CModbusFactory::prepareBattDatagram(char* pDataBuf, SMdobusTcpReq* pReq, CBattBank* pBattBank)
{
	// some variables
	int iByteNum = 0;	

	if (0 == pDataBuf || 0 == pReq || 0 == pBattBank)
	{
		return -1;
	}

	if (4 == pReq->uaFuncCode)
	{
		iByteNum = pReq->usRegNum * 2;

		if (iByteNum > 255) // 超出范围
		{
			return -3;
		}
	}
	else if(2 == pReq->uaFuncCode)
	{
		if (0 == pReq->usRegNum % 8)
		{
			iByteNum = pReq->usRegNum / 8;
		}
		else
		{
			iByteNum = pReq->usRegNum / 8 + 1;
		}

		if (iByteNum > 255) // 超出范围
		{
			return -3;
		}
	}
	else
	{
		return -2;
	}
	
	// Head
	int iLenVal = 0;	
	quint16 usRetRegNum = 0;
	memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

	// some variables  
	// 计算字节数
	quint16 usTemp = 0;

	addParam2Buffer(pDataBuf, pReq->usEvent);
	iLenVal += 2;                               // 事务标识

	addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
	iLenVal += 2;                               // 协议标识

	usTemp = (quint16)(iByteNum + 3);           // 长度
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pDataBuf + iLenVal) = pReq->uaAddr;
	iLenVal += 1;

	*(pDataBuf + iLenVal) = pReq->uaFuncCode;
	iLenVal += 1;

	*(pDataBuf + iLenVal) = (uchar)(iByteNum); // 字节数
	iLenVal += 1;

	if (2 == pReq->uaFuncCode) // 离散
	{
		for (quint16 usIndex = 0; usIndex < pReq->usRegNum;) // 离散寄存器
		{
			addRegVal2BufferBankDis(pDataBuf + iLenVal, pReq->usRegAddr + usIndex, pBattBank);

			usIndex += 8;

			iLenVal += 1;			
		}
	}
	else
	{	
		for (quint16 usIndex = 0; usIndex < pReq->usRegNum;) // 寄存器
		{
			usRetRegNum = addRegVal2BufferBank(pDataBuf + iLenVal, pReq->usRegAddr + usIndex, pBattBank);

			iLenVal += usRetRegNum * 2;

			usIndex += usRetRegNum;
		}
	}
	
	return iLenVal;
}

// >= 0 OK 
// -1 参数错误 
// -2 类型错误 
// -3 无告警缓存
int CModbusFactory::prepareAlarmCacheDatagram(char* pDataBuf, SMdobusTcpReq* pReq, CBattBank* pBattBank, CBankAlarm* pBankAlarm)
{
	if (0 == pDataBuf || 0 == pReq || 0 == pBattBank || 0 == pBankAlarm)
	{
		return -1;
	}

	// some variables
	SAlarmCache* pAlarmCache = 0;

	if (1 == pReq->usRegAddr) // 类型  1 -请求    2-确认
	{
		if(pBattBank->aAlarmAvailable > 0 && (pBankAlarm->usFirstCacheNo != pBankAlarm->usLastCacheNo))
		{
			pAlarmCache = &(pBankAlarm->alarmCache[pBankAlarm->usFirstCacheNo]);		
		}
		else 
		{
			return -3;
		}	
	}
	else if(2 == pReq->usRegAddr)
	{
		if (pBankAlarm->usFirstCacheNo == pReq->usRegNum) // 告警缓存序号
		{
			// 调整索引
			if (pBankAlarm->usFirstCacheNo >= MAX_ALARM_CACHE_NUM - 1)
			{
				pBankAlarm->usFirstCacheNo = 0;
			}
			else
			{
				++pBankAlarm->usFirstCacheNo;
			}			
		}

		if(pBattBank->aAlarmAvailable > 0 && (pBankAlarm->usFirstCacheNo != pBankAlarm->usLastCacheNo))
		{
			pAlarmCache = &(pBankAlarm->alarmCache[pBankAlarm->usFirstCacheNo]);		
		}
		else 
		{
			return 0;
		}	
	}
	else
	{
		return -2;
	}

	if (!pAlarmCache)
	{
		return -3;
	}

	// Head
	int iLenVal = 0;	
	quint16 usTemp = 0;

	memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

	addParam2Buffer(pDataBuf, pReq->usEvent);
	iLenVal += 2;                               // 事务标识

	addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
	iLenVal += 2;                               // 协议标识

	usTemp = 30;                                // 长度
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pDataBuf + iLenVal) = pReq->uaAddr;
	iLenVal += 1;

	*(pDataBuf + iLenVal) = pReq->uaFuncCode;
	iLenVal += 1;

	*(pDataBuf + iLenVal) = 27;                 // 字节数
	iLenVal += 1;

	usTemp = pBankAlarm->usFirstCacheNo;         // 告警编码
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	usTemp = pAlarmCache->usYear;               // 告警时间-年 
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pDataBuf + iLenVal) = (char)(pAlarmCache->usMonth);  // 告警时间-月
	iLenVal += 1;

	*(pDataBuf + iLenVal) = (char)(pAlarmCache->usDay);    // 告警时间-日
	iLenVal += 1;

	*(pDataBuf + iLenVal) = (char)(pAlarmCache->usHour);  // 告警时间-时
	iLenVal += 1;

	*(pDataBuf + iLenVal) = (char)(pAlarmCache->usMin);   // 告警时间-分
	iLenVal += 1;

	*(pDataBuf + iLenVal) = (char)(pAlarmCache->usSec);   // 告警时间-秒
	iLenVal += 1;

	usTemp = pAlarmCache->usMsec;                         // 告警时间-毫秒 
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pDataBuf + iLenVal) = (char)(pAlarmCache->usType);  // 离散寄存器地址
	iLenVal += 1;

	usTemp = pAlarmCache->usCellNo;                       // 电池节号 
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pDataBuf + iLenVal) = (char)(pAlarmCache->usAlmVal);      // 告警值  1  0--无告警，1--告警
	iLenVal += 1;

	addParam2Buffer(pDataBuf + iLenVal, pAlarmCache->fSampVal); // 告警发生时采样值
	iLenVal += 4;

	addParam2Buffer(pDataBuf + iLenVal, pAlarmCache->fThreVal); // 设置告警阈值 
	iLenVal += 4;

	usTemp = pAlarmCache->usNo1;                                // 序号1 
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	usTemp = pAlarmCache->usNo2;                                // 序号2
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;	

	return iLenVal;
}

// >= 0 OK 
// -1 参数错误 
// -2 功能码错误 
// -3 超出范围
int CModbusFactory::prepareBankAlarmDatagram(char* pDataBuf, SMdobusTcpReq* pReq, SAlarmParam* pAlarmParam, CBattBank* pBattBank, CBattStack* pBattStack)
{
	if (0 == pDataBuf || 0 == pReq || 0 == pAlarmParam || 0 == pBattBank || 0 == pBattStack)
	{
		return -1;
	}	

	// some variables 
	int iLenVal = 0;	
	quint16 usTemp = 0;

	if (3 == pReq->uaFuncCode)  // 读保持寄存器
	{
		memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

		addParam2Buffer(pDataBuf, pReq->usEvent);
		iLenVal += 2;                               // 事务标识

		addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
		iLenVal += 2;                               // 协议标识

		if (pReq->usRegNum * 2 > 255) // 超出范围
		{
			iLenVal = -4;
		}
		else
		{
			usTemp = pReq->usRegNum * 2 + 3;            // 长度
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = (char)(pReq->usRegNum * 2); // 字节数
			iLenVal += 1;

			for(quint16 usIndex = 0; usIndex < pReq->usRegNum; ++usIndex) // 寄存器
			{
				addHoldRegVal2BufferAlarm(pDataBuf + iLenVal, pReq->usRegAddr + usIndex, pAlarmParam, pBattBank);

				iLenVal += 2;
			}
		}
	}
	else if (6 == pReq->uaFuncCode)  // 写保持寄存器(单)
	{
		// Data
		if(setAlarmHoldRegVal(pReq->usRegAddr, pReq->usRegNum, pAlarmParam, pBattBank, pBattStack) >= 0)
		{
			memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

			addParam2Buffer(pDataBuf, pReq->usEvent);
			iLenVal += 2;                               // 事务标识

			addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
			iLenVal += 2;                               // 协议标识

			usTemp = 6;
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;                               // 长度

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegAddr);
			iLenVal += 2;                               // 寄存器地址

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegNum);
			iLenVal += 2;                               // 寄存器值
		}
		else
		{
			iLenVal = -5;
		}
	}
	else if (16 == pReq->uaFuncCode) // 写保持寄存器(多)
	{
		// Data
		iLenVal = 13; // 2事务标识 + 2协议标识 + 2长度 + 1地址 + 1功能码 + 2寄存器地址 + 2寄存器个数 + 1字节数 
		for(quint16 usIndex = 0; usIndex < pReq->usRegNum; ++usIndex) // 寄存器
		{
			getParamFromBuffer(pDataBuf + iLenVal, usTemp);		

			if(setAlarmHoldRegVal(pReq->usRegAddr + usIndex, usTemp, pAlarmParam, pBattBank, pBattStack) < 0)
			{
				iLenVal = -5;
				break;
			}

			iLenVal += 2;
		}

		if (iLenVal > 0)
		{
			memset(pDataBuf, 0, SNED_BUFFER_LENGHT);
			addParam2Buffer(pDataBuf, pReq->usEvent);
			iLenVal = 2;                               // 事务标识

			addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
			iLenVal += 2;                               // 协议标识

			usTemp = 6;
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;                               // 长度

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegAddr);
			iLenVal += 2;                               // 寄存器地址

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegNum);
			iLenVal += 2;                               // 寄存器值
		}		
	}
	else
	{
		iLenVal = -2;
	}

	return iLenVal;
}

// >= 0 OK 
// -1 参数错误 
// -2 功能码错误 
// -3 地址超出范围
// -4 超出范围
// -5 设置保持寄存器错误
int CModbusFactory::prepareUpdateDatagram(char* pDataBuf, SMdobusTcpReq* pReq, CBattStack* pBattStack)
{
	if (0 == pDataBuf || 0 == pReq || 0 == pBattStack)
	{
		return -1;
	}	

	// some variables 
	int iLenVal = 0;	
	quint16 usRetRegNum = 0;
	quint16 usTemp = 0;

	if (4 == pReq->uaFuncCode)       // 输入寄存器
	{
		memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

		addParam2Buffer(pDataBuf, pReq->usEvent);
		iLenVal += 2;                               // 事务标识

		addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
		iLenVal += 2;                               // 协议标识

		if (pReq->usRegNum * 2 > 255) // 超出范围
		{
			iLenVal = -4;
		}
		else
		{
			usTemp = pReq->usRegNum * 2 + 3;            // 长度
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = (char)(pReq->usRegNum * 2); // 字节数
			iLenVal += 1;

			for(quint16 usIndex = 0; usIndex < pReq->usRegNum;) // 寄存器
			{
				usRetRegNum = addRegVal2BufferUpdate(pDataBuf + iLenVal, pReq->usRegAddr + usIndex, pBattStack);

				iLenVal += usRetRegNum * 2;

				usIndex += usRetRegNum;
			}
		}
	}
	else if (3 == pReq->uaFuncCode)  // 读保持寄存器
	{
		memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

		addParam2Buffer(pDataBuf, pReq->usEvent);
		iLenVal += 2;                               // 事务标识

		addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
		iLenVal += 2;                               // 协议标识

		if (pReq->usRegNum * 2 > 255) // 超出范围
		{
			iLenVal = -4;
		}
		else
		{
			usTemp = pReq->usRegNum * 2 + 3;            // 长度
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = (char)(pReq->usRegNum * 2); // 字节数
			iLenVal += 1;

			for(quint16 usIndex = 0; usIndex < pReq->usRegNum; ++usIndex) // 寄存器
			{
				addHoldRegVal2BufferUpdate(pDataBuf + iLenVal, pReq->usRegAddr + usIndex, pBattStack);

				iLenVal += 2;
			}
		}
	}
	else if (6 == pReq->uaFuncCode)  // 写保持寄存器(单)
	{
		// Data
		if(setUpdateHoldRegVal(pReq->usRegAddr, pReq->usRegNum, pBattStack) >= 0)
		{
			memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

			addParam2Buffer(pDataBuf, pReq->usEvent);
			iLenVal += 2;                               // 事务标识

			addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
			iLenVal += 2;                               // 协议标识

			usTemp = 6;
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;                               // 长度

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegAddr);
			iLenVal += 2;                               // 寄存器地址

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegNum);
			iLenVal += 2;                               // 寄存器值
		}
		else
		{
			iLenVal = -5;
		}
	}
	else if (16 == pReq->uaFuncCode) // 写保持寄存器(多)
	{
		// Data
		iLenVal = 13; // 2事务标识 + 2协议标识 + 2长度 + 1地址 + 1功能码 + 2寄存器地址 + 2寄存器个数 + 1字节数 
		for(quint16 usIndex = 0; usIndex < pReq->usRegNum; ++usIndex) // 寄存器
		{
			getParamFromBuffer(pDataBuf + iLenVal, usTemp);		

			if(setUpdateHoldRegVal(pReq->usRegAddr + usIndex, usTemp, pBattStack) < 0)
			{
				iLenVal = -5;
				break;
			}

			iLenVal += 2;
		}

		if (iLenVal > 0)
		{
			memset(pDataBuf, 0, SNED_BUFFER_LENGHT);
			addParam2Buffer(pDataBuf, pReq->usEvent);
			iLenVal = 2;                               // 事务标识

			addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
			iLenVal += 2;                               // 协议标识

			usTemp = 6;
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;                               // 长度

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegAddr);
			iLenVal += 2;                               // 寄存器地址

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegNum);
			iLenVal += 2;                               // 寄存器值
		}		
	}
	else
	{
		iLenVal = -2;
	}

	return iLenVal;
}

// >= 0 OK 
// -1 参数错误 
// -2 功能码错误 
// -3 地址超出范围
// -4 超出范围
// -5 设置保持寄存器错误
int CModbusFactory::prepareStackDatagram(char* pDataBuf, SMdobusTcpReq* pReq, CBattStack* pBattStack)
{
	if (0 == pDataBuf || 0 == pReq || 0 == pBattStack)
	{
		return -1;
	}	

	// some variables 
	int iLenVal = 0;	
	quint16 usRetRegNum = 0;
	quint16 usTemp = 0;
	
	if (4 == pReq->uaFuncCode)       // 输入寄存器
	{
		memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

		addParam2Buffer(pDataBuf, pReq->usEvent);
		iLenVal += 2;                               // 事务标识

		addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
		iLenVal += 2;                               // 协议标识

		//if (pReq->usRegAddr > 84) // 寄存器地址超出范围
		//{
		//	return -3;
		//}

		if (pReq->usRegNum * 2 > 255) // 超出范围
		{
			iLenVal = -4;
		}
		else
		{
			usTemp = pReq->usRegNum * 2 + 3;            // 长度
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = (char)(pReq->usRegNum * 2); // 字节数
			iLenVal += 1;

			for(quint16 usIndex = 0; usIndex < pReq->usRegNum;) // 寄存器
			{
				usRetRegNum = addRegVal2BufferStack(pDataBuf + iLenVal, pReq->usRegAddr + usIndex, pBattStack);

				iLenVal += usRetRegNum * 2;

				usIndex += usRetRegNum;
			}
		}
	}
	else if (3 == pReq->uaFuncCode)  // 读保持寄存器
	{
		memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

		addParam2Buffer(pDataBuf, pReq->usEvent);
		iLenVal += 2;                               // 事务标识

		addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
		iLenVal += 2;                               // 协议标识

		if (pReq->usRegNum * 2 > 255) // 超出范围
		{
			iLenVal = -4;
		}
		else
		{
			usTemp = pReq->usRegNum * 2 + 3;            // 长度
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = (char)(pReq->usRegNum * 2); // 字节数
			iLenVal += 1;

			for(quint16 usIndex = 0; usIndex < pReq->usRegNum; ++usIndex) // 寄存器
			{
				addHoldRegVal2BufferStack(pDataBuf + iLenVal, pReq->usRegAddr + usIndex, pBattStack);

				iLenVal += 2;
			}
		}
	}
	else if (6 == pReq->uaFuncCode)  // 写保持寄存器(单)
	{
		// Data
		if(setStackHoldRegVal(pReq->usRegAddr, pReq->usRegNum, pBattStack) >= 0)
		{
			memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

			addParam2Buffer(pDataBuf, pReq->usEvent);
			iLenVal += 2;                               // 事务标识

			addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
			iLenVal += 2;                               // 协议标识

			usTemp = 6;
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;                               // 长度

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegAddr);
			iLenVal += 2;                               // 寄存器地址

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegNum);
			iLenVal += 2;                               // 寄存器值
		}
		else
		{
			iLenVal = -5;
		}
	}
	else if (16 == pReq->uaFuncCode) // 写保持寄存器(多)
	{
		// Data
		iLenVal = 13; // 2事务标识 + 2协议标识 + 2长度 + 1地址 + 1功能码 + 2寄存器地址 + 2寄存器个数 + 1字节数 
		for(quint16 usIndex = 0; usIndex < pReq->usRegNum; ++usIndex) // 寄存器
		{
			getParamFromBuffer(pDataBuf + iLenVal, usTemp);		

			if(setStackHoldRegVal(pReq->usRegAddr + usIndex, usTemp, pBattStack) < 0)
			{
				iLenVal = -5;
				break;
			}

			iLenVal += 2;
		}

		if (iLenVal > 0)
		{
			memset(pDataBuf, 0, SNED_BUFFER_LENGHT);
			addParam2Buffer(pDataBuf, pReq->usEvent);
			iLenVal = 2;                               // 事务标识

			addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
			iLenVal += 2;                               // 协议标识

			usTemp = 6;
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;                               // 长度

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegAddr);
			iLenVal += 2;                               // 寄存器地址

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegNum);
			iLenVal += 2;                               // 寄存器值
		}		
	}
	else
	{
		iLenVal = -2;
	}

	return iLenVal;
}

// >= 0 OK 
// -1 参数错误
int CModbusFactory::prepareExcepDatagram(char* pDataBuf, SMdobusTcpReq* pReq, uchar uaExcepCode)
{
	if (0 == pDataBuf || 0 == pReq)
	{
		return -1;
	}

	int iLenVal = 0;	
	memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

	// some variables
	quint16 usTemp = 0;

	addParam2Buffer(pDataBuf, pReq->usEvent);
	iLenVal += 2;                               // 事务标识

	addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
	iLenVal += 2;                               // 协议标识

	usTemp = 3;                                  // 长度
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pDataBuf + iLenVal) = pReq->uaAddr;
	iLenVal += 1;

	*(pDataBuf + iLenVal) = (pReq->uaFuncCode + 0x80);
	iLenVal += 1;

	*(pDataBuf + iLenVal) = uaExcepCode;
	iLenVal += 1;

	return iLenVal;
}

// >= 0 OK 
// -1 参数错误 
// -2 地址超出范围
// -3 功能码错误 
// -4 超出范围
// -5 写保持寄存器地址不正确
int CModbusFactory::prepareBAComHoldRegDatagram(char* pDataBuf, SMdobusTcpReq* pReq, quint16* pComHoldRegData)
{
	if (0 == pDataBuf || 0 == pReq || 0 == pComHoldRegData)
	{
		return -1;
	}

	if (pReq->usRegAddr > 50 || pReq->usRegAddr < 1) // 寄存器地址超出范围
	{
		return -2;
	}

	// Head
	int iLenVal = 0;	
	memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

	// some variables  
	// 计算字节数
	quint16 usTemp = 0;

	if (3 == pReq->uaFuncCode)     // 读保持寄存器 
	{
		if (pReq->usRegNum * 2 > 255) // 超出范围
		{
			iLenVal = -4;
		}
		else
		{
			addParam2Buffer(pDataBuf, pReq->usEvent);
			iLenVal += 2;                               // 事务标识

			addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
			iLenVal += 2;                               // 协议标识

			usTemp = pReq->usRegNum * 2 + 3;            // 长度
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = (char)(pReq->usRegNum * 2); // 字节数
			iLenVal += 1;

			// data	
			for(quint16 usIndex = 0; usIndex < pReq->usRegNum; ++usIndex) // 寄存器
			{
				if (pReq->usRegAddr - 1 + usIndex < 50)
				{
					usTemp = *(pComHoldRegData + pReq->usRegAddr - 1 + usIndex);
				}
				else
				{
					usTemp = 0;
				}

				addParam2Buffer(pDataBuf + iLenVal, usTemp);
				iLenVal += 2;
			}
		}
	}
	else if (6 == pReq->uaFuncCode) // 写保持寄存器
	{
		iLenVal = pReq->usRegAddr - 1;

		if (iLenVal >= 0 && iLenVal < 50)
		{
			pComHoldRegData[iLenVal] = pReq->usRegNum;

			iLenVal = formDatagram(pReq->usEvent, pReq->uaAddr, pReq->uaFuncCode, pReq->usRegAddr, pReq->usRegNum, pDataBuf);
		}
		else
		{
			iLenVal = -5;
		}		
	}
	else
	{
		return -3;
	}

	return iLenVal;
}

// >= 0 OK 
// -1 参数错误 
// -2 功能码错误 
// -3 地址超出范围
// -4 超出范围
int CModbusFactory::prepareBAComInputRegDatagram(char* pDataBuf, SMdobusTcpReq* pReq, quint16* pComInputRegData)
{
	if (0 == pDataBuf || 0 == pReq || 0 == pComInputRegData)
	{
		return -1;
	}

	if (4 != pReq->uaFuncCode) // 输入寄存器 功能码
	{
		return -2;
	}

	if (pReq->usRegAddr > 100 || pReq->usRegAddr < 1) // 寄存器地址超出范围
	{
		return -3;
	}

	if (pReq->usRegNum * 2 > 255) // 超出范围
	{
		return -4;
	}

	// Head
	int iLenVal = 0;	
	memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

	// some variables  
	// 计算字节数
	quint16 usTemp = 0;

	addParam2Buffer(pDataBuf, pReq->usEvent);
	iLenVal += 2;                               // 事务标识

	addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
	iLenVal += 2;                               // 协议标识

	usTemp = pReq->usRegNum * 2 + 3;            // 长度
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pDataBuf + iLenVal) = pReq->uaAddr;
	iLenVal += 1;

	*(pDataBuf + iLenVal) = pReq->uaFuncCode;
	iLenVal += 1;

	*(pDataBuf + iLenVal) = (char)(pReq->usRegNum * 2); // 字节数
	iLenVal += 1;

	// data	
	for(quint16 usIndex = 0; usIndex < pReq->usRegNum; ++usIndex) // 寄存器
	{
		if (pReq->usRegAddr - 1 + usIndex < 100)
		{
			usTemp = *(pComInputRegData + pReq->usRegAddr - 1 + usIndex);
		}
		else
		{
			usTemp = 0;
		}

		addParam2Buffer(pDataBuf + iLenVal, usTemp);
		iLenVal += 2;
	}

	return iLenVal;
}

// 返回处理的寄存器个数(处理8个寄存器)
// 返回 8 的倍数
void CModbusFactory::addRegVal2BufferBankDis(char* pData, quint16 usRegAddr, CBattBank* pBattBank)
{
	if(!pData || !pBattBank)
	{
		return;     // 跳过该寄存器
	}

	uchar uaVal = 0;

	for(quint16 usIndex = 0; usIndex < 8; ++usIndex)
	{
		if (getRegValBankDis(usRegAddr + usIndex, pBattBank) > 0)
		{
			uaVal = uaVal | 0x80;
		}

		// 移位
		if(usIndex < 7) // 0 - 6
		{
			uaVal = uaVal >> 1;
		}
	}

	*pData = uaVal;
}

// -1 - Not find
//  0 - bool false
//  > 0 - bool true
int CModbusFactory::getRegValBankDis(quint16 usRegAddr, CBattBank* pBattBank)
{
	if (!pBattBank)
	{
		return -1;
	}

	// some variables
	int iRetVal = -1;

	if (usRegAddr >= 1 && usRegAddr <= 80)
	{
		if (1 == usRegAddr)
		{
			iRetVal = pBattBank->aBankVolUpLimitWarn;	     // 组电压上限预警                 1	
		}
		else if (2 == usRegAddr)
		{
			iRetVal = pBattBank->aBankVolDownLimitWarn;      // 组电压下限预警                 2
		}
		else if (3 == usRegAddr)
		{
			iRetVal = pBattBank->aChgCurUpLimitWarn;		 // 充电电流上限预警               3 
		}
		else if (4 == usRegAddr)
		{
			iRetVal = pBattBank->aDchgCurUpLimitWarn;		 // 放电电流上限预警               4
		}
		else if (5 == usRegAddr)
		{
			iRetVal = pBattBank->aSglVolUpLimitWarn;	     // 单体电压上限预警	           5
		}
		else if (6 == usRegAddr)
		{
			iRetVal = pBattBank->aSglVolDownLimitWarn;	     // 单体电压下限预警	           6
		}
		else if (7 == usRegAddr)
		{
			iRetVal = pBattBank->aChgTempUpLimitWarn;	     // 充电温度上限预警	           7	
		}
		else if (8 == usRegAddr)
		{
			iRetVal = pBattBank->aChgTempDownLimitWarn;	     // 充电温度下限预警               8
		}
		else if (9 == usRegAddr)
		{
			iRetVal = pBattBank->aDchgTempUpLimitWarn;	     // 放电温度上限预警	           9	
		}
		else if (10 == usRegAddr)
		{
			iRetVal = pBattBank->aDchgTempDownLimitWarn;	 // 放电温度下限预警               10
		}
		else if (11 == usRegAddr)
		{
			iRetVal = pBattBank->aSglTempUpLimitWarn;	     // 单体温度上限预警	           11
		}
		else if (12 == usRegAddr)
		{
			iRetVal = pBattBank->aSglTempDownLimitWarn;	     // 单体温度下限预警               12
		}
		else if (13 == usRegAddr)
		{
			iRetVal = pBattBank->aEnvTempUpLimitWarn;		 // 环境温度上限预警	           13
		}
		else if (14 == usRegAddr)
		{
			iRetVal = pBattBank->aEnvTempDownLimitWarn;	     // 环境温度下限预警	           14
		}
		else if (15 == usRegAddr)
		{
			iRetVal = pBattBank->aPowerLineTempUpLimitWarn;	 // 动力线温度上限预警	           15
		}
		else if (16 == usRegAddr)
		{
			iRetVal = pBattBank->aBankSocUpLimitWarn;	     // SOC超上限预警		           16
		}
		else if (17 == usRegAddr)
		{
			iRetVal = pBattBank->aBankSocDownLimitWarn;	     // SOC超下限预警		           17
		}
		else if (18 == usRegAddr)
		{
			iRetVal = pBattBank->aPosResDownLimitWarn;		 // 正极绝缘内阻下限预警           18
		}
		else if (19 == usRegAddr)
		{
			iRetVal = pBattBank->aNegResDownLimitWarn;		 // 负极绝缘内阻下限预警           19
		}
		else if (20 == usRegAddr)
		{
			iRetVal = pBattBank->aPackVolDiffUpLimitWarn;	 // 箱压差上限预警                 20
		}
		else if (21 == usRegAddr)
		{
			iRetVal = pBattBank->aPackTempDiffUpLimitWarn;	 // 箱温差上限预警                 21
		}
		else if (22 == usRegAddr)
		{
			iRetVal = pBattBank->aBankVolUpLimitAlarm;	     // 组电压上限告警                 22
		}
		else if (23 == usRegAddr)
		{
			iRetVal = pBattBank->aBankVolDownLimitAlarm;     // 组电压下限告警                 23
		}
		else if (24 == usRegAddr)
		{
			iRetVal = pBattBank->aChgCurUpLimitAlarm;		 // 充电电流上限告警               24 
		}
		else if (25 == usRegAddr)
		{
			iRetVal = pBattBank->aDchgCurUpLimitAlarm;		 // 放电电流上限告警               25
		}
		else if (26 == usRegAddr)
		{
			iRetVal = pBattBank->aSglVolUpLimitAlarm;	     // 单体电压上限告警	           26
		}
		else if (27 == usRegAddr)
		{
			iRetVal = pBattBank->aSglVolDownLimitAlarm;	     // 单体电压下限告警	           27	
		}
		else if (28 == usRegAddr)
		{
			iRetVal = pBattBank->aChgTempUpLimitAlarm;	     // 充电温度上限告警	           28	
		}
		else if (29 == usRegAddr)
		{
			iRetVal = pBattBank->aChgTempDownLimitAlarm;	 // 充电温度下限告警               29
		}
		else if (30 == usRegAddr)
		{
			iRetVal = pBattBank->aDchgTempUpLimitAlarm;	     // 放电温度上限告警	           30
		}
		else if (31 == usRegAddr)
		{
			iRetVal = pBattBank->aDchgTempDownLimitAlarm;	 // 放电温度下限告警               31
		}
		else if (32 == usRegAddr)
		{
			iRetVal = pBattBank->aSglTempUpLimitAlarm;	     // 单体温度上限告警	           32
		}
		else if (33 == usRegAddr)
		{
			iRetVal = pBattBank->aSglTempDownLimitAlarm;	 // 单体温度下限告警               33
		}
		else if (34 == usRegAddr)
		{
			iRetVal = pBattBank->aEnvTempUpLimitAlarm;		 // 环境温度上限告警	           34
		}
		else if (35 == usRegAddr)
		{
			iRetVal = pBattBank->aEnvTempDownLimitAlarm;	 // 环境温度下限告警	           35
		}
		else if (36 == usRegAddr)
		{
			iRetVal = pBattBank->aPowerLineTempUpLimitAlarm; // 动力线温度上限告警	           36
		}
		else if (37 == usRegAddr)
		{
			iRetVal = pBattBank->aBankSocUpLimitAlarm;	     // SOC超上限告警		           37
		}
		else if (38 == usRegAddr)
		{
			iRetVal = pBattBank->aBankSocDownLimitAlarm;	 // SOC超下限告警		           38
		}
		else if (39 == usRegAddr)
		{
			iRetVal = pBattBank->aPosResDownLimitAlarm;		 // 正极绝缘内阻下限告警           39
		}
		else if (40 == usRegAddr)
		{
			iRetVal = pBattBank->aNegResDownLimitAlarm;		 // 负极绝缘内阻下限告警           40
		}
		else if (41 == usRegAddr)
		{
			iRetVal = pBattBank->aPackVolDiffUpLimitAlarm;	 // 箱压差上限告警                 41
		}
		else if (42 == usRegAddr)
		{
			iRetVal = pBattBank->aPackTempDiffUpLimitAlarm;	 // 箱温差上限告警                 42
		}
		else if (43 == usRegAddr)
		{
			iRetVal = pBattBank->aBankVolUpLimitProt;	     // 组电压上限保护                 43
		}
		else if (44 == usRegAddr)
		{
			iRetVal = pBattBank->aBankVolDownLimitProt;      // 组电压下限保护                 44
		}
		else if (45 == usRegAddr)
		{
			iRetVal = pBattBank->aChgCurUpLimitProt;		 // 充电电流上限保护               45 
		}
		else if (46 == usRegAddr)
		{
			iRetVal = pBattBank->aDchgCurUpLimitProt;		 // 放电电流上限保护               46
		}
		else if (47 == usRegAddr)
		{
			iRetVal = pBattBank->aSglVolUpLimitProt;	     // 单体电压上限保护	           47
		}
		else if (48 == usRegAddr)
		{
			iRetVal = pBattBank->aSglVolDownLimitProt;	     // 单体电压下限保护	           48	
		}
		else if (49 == usRegAddr)
		{
			iRetVal = pBattBank->aChgTempUpLimitProt;	     // 充电温度上限保护	           49
		}
		else if (50 == usRegAddr)
		{
			iRetVal = pBattBank->aChgTempDownLimitProt;	     // 充电温度下限保护               50
		}
		else if (51 == usRegAddr)
		{
			iRetVal = pBattBank->aDchgTempUpLimitProt;	     // 放电温度上限保护	           51	
		}
		else if (52 == usRegAddr)
		{
			iRetVal = pBattBank->aDchgTempDownLimitProt;	 // 放电温度下限保护               52
		}
		else if (53 == usRegAddr)
		{
			iRetVal = pBattBank->aSglTempUpLimitProt;	     // 单体温度上限保护	           53	
		}
		else if (54 == usRegAddr)
		{
			iRetVal = pBattBank->aSglTempDownLimitProt;	     // 单体温度下限保护               54
		}
		else if (55 == usRegAddr)
		{
			iRetVal = pBattBank->aEnvTempUpLimitProt;		 // 环境温度上限保护	           55
		}
		else if (56 == usRegAddr)
		{
			iRetVal = pBattBank->aEnvTempDownLimitProt;	     // 环境温度下限保护	           56
		}
		else if (57 == usRegAddr)
		{
			iRetVal = pBattBank->aPowerLineTempUpLimitProt;	 // 动力线温度上限保护	           57
		}
		else if (58 == usRegAddr)
		{
			iRetVal = pBattBank->aBankSocUpLimitProt;	     // SOC超上限保护		           58
		}
		else if (59 == usRegAddr)
		{
			iRetVal = pBattBank->aBankSocDownLimitProt;	     // SOC超下限保护		           59
		}
		else if (60 == usRegAddr)
		{
			iRetVal = pBattBank->aPosResDownLimitProt;		 // 正极绝缘内阻下限保护           60
		}
		else if (61 == usRegAddr)
		{
			iRetVal = pBattBank->aNegResDownLimitProt;		 // 负极绝缘内阻下限保护           61
		}
		else if (62 == usRegAddr)
		{
			iRetVal = pBattBank->aPackVolDiffUpLimitProt;	 // 箱压差上限保护                 62
		}
		else if (63 == usRegAddr)
		{
			iRetVal = pBattBank->aPackTempDiffUpLimitProt;	 // 箱温差上限保护                 63
		}
		else if (64 == usRegAddr)
		{
			iRetVal = pBattBank->aSglTempRise;	             // 电池温度温升过快               64
		}
		else if (65 == usRegAddr)
		{
			iRetVal = pBattBank->aPowerLineTempRise;	     // 动力线温度温升过快             65
		}
		else if (66 == usRegAddr)
		{
			iRetVal = pBattBank->aBMUConnFault;		         // BMU通讯故障	                   66
		}
		else if (67 == usRegAddr)
		{
			iRetVal = pBattBank->aBCMUConnFault;		     // BCMU通讯故障                   67	
		}
		else if (68 == usRegAddr)
		{
			iRetVal = pBattBank->aSglVolWireFault;           // 单体电压采集线故障             68
		}
		else if (69 == usRegAddr)
		{
			iRetVal = pBattBank->aBankVolWireFault;          // 总压采集线故障                 69
		}
		else if (70 == usRegAddr)
		{
			iRetVal = pBattBank->aCurWireFault;              // 电流采集线故障                 70
		}
		else if (71 == usRegAddr)
		{
			iRetVal = pBattBank->aTempWireBreak;             // 温度采集断线                   71
		}
		else if (72 == usRegAddr)
		{
			iRetVal = pBattBank->aTempShortCircuit;          // 温度采集短路                   72
		}
		else if (73 == usRegAddr)
		{
			iRetVal = pBattBank->aBMSFault;                  // BMS设备故障                    73
		}
		else if (74 == usRegAddr)
		{
			iRetVal = pBattBank->aSglVolInvalid;             // 单体电压无效                   74
		}
		else if (75 == usRegAddr)
		{
			iRetVal = pBattBank->aSglTempInvalid;            // 单体温度无效                   75
		}
		else if (76 == usRegAddr)
		{
			iRetVal = pBattBank->aBankVolInvalid;            // 组端电压无效                   76
		}
		else if (77 == usRegAddr)
		{
			iRetVal = pBattBank->aBankCurAbnormity;          // 组电流异常                     77  
		}
		else if (78 == usRegAddr)
		{
			iRetVal = pBattBank->aFireAlarm;                 // 消防报警                       78
		}
		else if (79 == usRegAddr)
		{
			iRetVal = pBattBank->aWaterAlarm;                // 水浸报警                       79
		}
		else if (80 == usRegAddr)
		{
			iRetVal = pBattBank->aAlarmAvailable;            // 告警信息待获取                 80	
		}
		else if (usRegAddr >= 101 && usRegAddr <= 500)
		{
			iRetVal = pBattBank->aChgEquState[usRegAddr - 101]; // 充电均衡状态                   101 ~ 500
		}
		else if (usRegAddr >= 501 && usRegAddr <= 900)
		{
			iRetVal = pBattBank->aDchgEquState[usRegAddr - 501]; // 放电均衡状态                   501 ~ 900
		}		
		else
		{
			iRetVal = -1;
		}
	}	
	else
	{
		iRetVal = -1;
	}

	return iRetVal;
}

// 返回处理的寄存器个数
// 一个寄存器两个字节
quint16 CModbusFactory::addRegVal2BufferBank(char* pData, quint16 usRegAddr, CBattBank* pBattBank)
{
	if(!pData || !pBattBank)
	{
		return 1;     // 跳过该寄存器
	}

	quint16 usRetVal = 1;
	quint16 usTemp = 0;
	quint32 uiTemp = 0;
	float fTemp = 0;

	int iRetVal = getRegValBank(usRegAddr, pBattBank, usTemp, fTemp, uiTemp);
	if (1 == iRetVal)
	{
		addParam2Buffer(pData, usTemp);
		usRetVal = 1;
	}
	else if (2 == iRetVal)
	{
		addParam2Buffer(pData, fTemp);
		usRetVal = 2;
	}
	else if (3 == iRetVal)
	{
		addParam2Buffer(pData, uiTemp);
		usRetVal = 2;
	}
	else
	{
		usRetVal = 1;
	}

	return usRetVal;	
}

// -1 - Not find
//  1 - quint16 类型
//  2 - float 类型
//  3 - quint32
int CModbusFactory::getRegValBank(quint16 usRegAddr, CBattBank* pBattBank, quint16& usVal, float& fVal, quint32& uiVal)
{
	if (!pBattBank)
	{
		return -1;
	}

	// some variables
	int iRetVal = -1;

	if(usRegAddr >= 0x2001 && usRegAddr <= 0x201F)
	{
		if (0x2001 == usRegAddr)
		{
			usVal = pBattBank->usBankState;				  // 电池组状态                        0x2001    0 - 正常   1 - 禁充    2 - 禁放    3 - 待机     4 - 停机
			iRetVal = 1;	
		}
		else if (0x2002 == usRegAddr)
		{
			usVal = pBattBank->usBankChgDchgState; 		  // 电池组充放电状态	               0x2002    0 - 静止   1 - 放电    2 - 充电
			
			if (1 == usVal)
			{
				usVal = 0;
			}
			else if (2 == usVal)
			{
				usVal = 0;
			}
			else if (3 == usVal)
			{
				usVal = 2;
			}
			else if (4 == usVal)
			{
				usVal = 1;
			}
			else
			{
				usVal = 0;
			}

			iRetVal = 1;	
		}
		else if (0x2003 == usRegAddr)
		{
			usVal = pBattBank->usBankCntorState;			  // 电池组接触器状态                  0x2003
			iRetVal = 1;	
		}
		else if (0x2004 == usRegAddr)
		{
			usVal = pBattBank->usBankTotAlarm;				  // 电池组总告警                      0x2004
			iRetVal = 1;	
		}
		else if (0x2005 == usRegAddr)
		{
			usVal = pBattBank->usBankWarn;					  // 电池组预警                        0x2005
			iRetVal = 1;	
		}
		else if (0x2006 == usRegAddr)
		{
			usVal = pBattBank->usBankAlarm;                  // 电池组告警                        0x2006
			iRetVal = 1;	
		}
		else if (0x2007 == usRegAddr)
		{
			usVal = pBattBank->usBankCritical;               // 电池组严重                        0x2007	
			iRetVal = 1;	
		}
		else if (0x2008 == usRegAddr)
		{
			usVal = pBattBank->usBankStepInFailReas;         // 电池组切入失败原因                0x2008
			iRetVal = 1;	
		}
		else if (0x2009 == usRegAddr || 0x200A == usRegAddr)
		{
			usVal = 0;
			iRetVal = 1;	
		}
		else if (0x200B == usRegAddr)
		{
			usVal = (quint16)(pBattBank->fBankVol * 10);      // 组端电压						   0x200B
			iRetVal = 1;	
		}
		else if (0x200C == usRegAddr)
		{
			usVal = (qint16)(pBattBank->fBankCur * -10);	  // 组电流							   0x200C
			iRetVal = 1;	
		}
		else if (0x200D == usRegAddr)
		{
			usVal = pBattBank->usBankChgDchgState; 	  

			if (1 == usVal)
			{
				usVal = 0;
			}
			else if (2 == usVal)
			{
				usVal = 0;
			}
			else if (3 == usVal)
			{
				usVal = 2;
			}
			else if (4 == usVal)
			{
				usVal = 1;
			}
			else
			{
				usVal = 0;
			}

			iRetVal = 1;
		}
		else if (0x200E == usRegAddr)
		{
			usVal = (quint16)(pBattBank->fBankSoc * 10);	   // 组SOC		                       0x200E
			iRetVal = 1;	
		}
		else if (0x200F == usRegAddr)
		{
			usVal = (quint16)(pBattBank->fBankSoh * 10);      // 组SOH	                           0x200F
			iRetVal = 1;	
		}
		else if (0x2010 == usRegAddr)
		{
			usVal = (quint16)(pBattBank->fInsuRes * 100); 					  // 绝缘电阻	                       0x2010
			iRetVal = 1;	
		}
		else if (0x2011 == usRegAddr)
		{
			usVal = (quint16)(pBattBank->fPosRes * 100); 						  // 正极绝缘电阻	                   0x2011
			iRetVal = 1;	
		}
		else if (0x2012 == usRegAddr)
		{
			usVal = (quint16)(pBattBank->fNegRes * 100);						  // 负极绝缘电阻	                   0x2012
			iRetVal = 1;	
		}
		else if (0x2013 == usRegAddr)
		{
			usVal = (quint16)(pBattBank->fBankAllowMaxChargeCurrent * 10);     // 电池组最大充电电流                0x2013 
			iRetVal = 1;	
		}
		else if (0x2014 == usRegAddr)
		{
			usVal = (quint16)(pBattBank->fBankAllowMaxDischargeCurrent * 10);  // 电池组最大放电电流                0x2014 
			iRetVal = 1;	
		}
		else if (0x2015 == usRegAddr)
		{
			usVal = pBattBank->usSglMaxVolNo;				  // 单体电压最大节号                  0x2015
			iRetVal = 1;	
		}
		else if (0x2016 == usRegAddr)
		{
			usVal = (quint16)(pBattBank->fSglMaxVol * 1000);  // 单电电压最大值                    0x2016		
			iRetVal = 1;	
		}
		else if (0x2017 == usRegAddr)
		{
			usVal = pBattBank->usSglMinVolNo;                // 单体电压最小节号                  0x2017
			iRetVal = 1;	
		}
		else if (0x2018 == usRegAddr)
		{
			usVal = (quint16)(pBattBank->fSglMinVol * 1000); // 单电电压最小值	                   0x2018	
			iRetVal = 1;	
		}
		else if (0x2019 == usRegAddr)
		{
			usVal = pBattBank->usSglMaxTempNo;               // 单体温度最大节号                  0x2019
			iRetVal = 1;	
		}
		else if (0x201A == usRegAddr)
		{
			usVal = (quint16)(pBattBank->fSglMaxTemp * 10);  // 单电温度最大值	                   0x201A	
			iRetVal = 1;	
		}
		else if (0x201B == usRegAddr)
		{
			usVal = pBattBank->usSglMinTempNo;               // 单体温度最小节号                  0x201B
			iRetVal = 1;	
		}
		else if (0x201C == usRegAddr)
		{
			usVal = (quint16)(pBattBank->fSglMinTemp * 10);  // 单电温度最小值	                   0x201C	
			iRetVal = 1;	
		}
		else if (0x201D == usRegAddr)
		{
			usVal = (quint16)(pBattBank->fSglAvgVol * 1000); // 单体电压平均值                    0x201D
			iRetVal = 1;	
		}
		else if (0x201E == usRegAddr)
		{
			usVal = (quint16)(pBattBank->fSglAvgTemp * 10);  // 单体温度平均值                    0x201E
			iRetVal = 1;	
		}
	}
	//else if (usRegAddr >= 0x2020 && usRegAddr <= 0x211F) // 单体电压                    
	//{
	//	usVal = (quint16)(pBattBank->fSglVol[usRegAddr - 0x2020] * 1000);
	//	iRetVal = 1;		
	//}	
	//else if (usRegAddr >= 0x2120 && usRegAddr <= 0x221F) // 单体温度                    
	//{
	//	usVal = (quint16)(pBattBank->fSglTemp[usRegAddr - 0x2120] * 10);
	//	iRetVal = 1;		
	//}	
	else if (usRegAddr >= 0x2020 && usRegAddr <= 0x2277) // 单体电压 Cell 600      
	{
		usVal = (quint16)(pBattBank->fSglVol[usRegAddr - 0x2020] * 1000);
		iRetVal = 1;		
	}	
	else if (usRegAddr >= 0x2278 && usRegAddr <= 0x24CF) // 单体温度 Cell 600                   
	{
		usVal = (quint16)(pBattBank->fSglTemp[usRegAddr - 0x2278] * 10);
		iRetVal = 1;		
	}
	else if (usRegAddr >= 1 && usRegAddr <= 200) // 1 ~ 200
	{
		if (1 == usRegAddr)
		{
			usVal = pBattBank->usBankState;             // 电池组状态                     1      0x1充满，0x2放空，0x3待机，0x4跳机，0x0正常 
			iRetVal = 1;
		}
		else if (2 == usRegAddr)
		{
			usVal = pBattBank->usBankChgDchgState; 	 // 电池组充放电状态	           2      1 - 开路 2 - 待机 3 - 充电  4 - 放电
			iRetVal = 1;
		}
		else if (3 == usRegAddr)
		{
			usVal = pBattBank->usCellNumInBank;         // 电池组管辖电池节数             3
			iRetVal = 1;
		}
		else if (4 == usRegAddr)
		{
			usVal = pBattBank->usTempNumInBank;         // 电池组管辖温度节数             4
			iRetVal = 1;
		}
		else if (5 == usRegAddr)
		{
			usVal = pBattBank->usPackNumInBank;         // 电池组管辖PACK数               5
			iRetVal = 1;
		}
		else if (6 == usRegAddr)
		{
			usVal = pBattBank->usSglMaxVolNo;           // 单体电压最大节号               6
			iRetVal = 1;
		}
		else if (7 == usRegAddr)
		{
			usVal = pBattBank->usSglMinVolNo;           // 单体电压最小节号               7
			iRetVal = 1;
		}
		else if (8 == usRegAddr)
		{
			usVal = pBattBank->usSglMaxTempNo;          // 单体温度最大节号               8
			iRetVal = 1;
		}
		else if (9 == usRegAddr)
		{
			usVal = pBattBank->usSglMinTempNo;          // 单体温度最小节号               9
			iRetVal = 1;
		}
		else if (10 == usRegAddr)
		{
			usVal = pBattBank->usSglMaxResNo;           // 单体内阻最大节号               10
			iRetVal = 1;
		}
		else if (11 == usRegAddr)
		{
			usVal = pBattBank->usSglMinResNo;           // 单体内阻最小节号               11
			iRetVal = 1;
		}
		else if (12 == usRegAddr)
		{
			usVal = pBattBank->usSglMaxSocNo;           // 单体SOC最大节号                12
			iRetVal = 1;
		}
		else if (13 == usRegAddr)
		{
			usVal = pBattBank->usSglMinSocNo;           // 单体SOC最小节号                13
			iRetVal = 1;
		}
		else if (14 == usRegAddr)
		{
			usVal = pBattBank->usSglMaxSohNo;           // 单体SOH最大节号                14
			iRetVal = 1;
		}
		else if (15 == usRegAddr)
		{
			usVal = pBattBank->usSglMinSohNo;           // 单体SOH最小节号                15	
			iRetVal = 1;
		}
		else if (16 == usRegAddr)
		{
			usVal = pBattBank->usDI1;				     // 开关量输入-DI1		           16     1--闭合， 0--断开
			iRetVal = 1;
		}
		else if (17 == usRegAddr)
		{
			usVal = pBattBank->usDI2; 	                 // 开关量输入-DI2                 17
			iRetVal = 1;
		}
		else if (18 == usRegAddr)
		{
			usVal = pBattBank->usDI3; 	                 // 开关量输入-DI3                 18
			iRetVal = 1;
		}
		else if (19 == usRegAddr)
		{
			usVal = pBattBank->usDI4; 	                 // 开关量输入-DI4		           19
			iRetVal = 1;
		}
		else if (20 == usRegAddr)
		{
			usVal = pBattBank->usDI5; 	                 // 开关量输入-DI5		           19
			iRetVal = 1;
		}
		else if (21 == usRegAddr)
		{
			usVal = pBattBank->usDI6; 	                 // 开关量输入-DI6		           19
			iRetVal = 1;
		}
		else if (22 == usRegAddr)
		{
			usVal = pBattBank->usChgNum; 	             // 充电次数		               20
			iRetVal = 1;
		}
		else if (23 == usRegAddr)
		{
			usVal = pBattBank->usDchgNum; 	             // 放电次数		               21
			iRetVal = 1;
		}
		else if (usRegAddr >= 24 && usRegAddr <= 50)
		{
			usVal = pBattBank->usBankTemp[usRegAddr - 24];
			iRetVal = 1;
		}

		else if (51 == usRegAddr)
		{
			fVal = pBattBank->fBankVol; 	             // 组端电压		               51 	      
			iRetVal = 2;
		}
		else if (53 == usRegAddr)
		{
			fVal = pBattBank->fBankCur; 	             // 组电流		                   53      
			iRetVal = 2;
		}
		else if (55 == usRegAddr)
		{
			fVal = pBattBank->fBankSoc;                  // 组SOC		                   55	      
			iRetVal = 2;
		}
		else if (57 == usRegAddr)
		{
			fVal = pBattBank->fBankSoh;                  // 组SOH	                       57	      
			iRetVal = 2;
		}
		else if (59 == usRegAddr)
		{
			fVal = pBattBank->fEnvTemp; 	             // 环境温度		               59	      
			iRetVal = 2;
		}
		else if (61 == usRegAddr)
		{
			fVal = pBattBank->fPosRes; 	                 // 正极绝缘电阻	               61	      
			iRetVal = 2;
		}
		else if (63 == usRegAddr)
		{
			fVal = pBattBank->fNegRes;                   // 负极绝缘电阻	               63      
			iRetVal = 2;
		}
		else if (65 == usRegAddr)
		{
			fVal = pBattBank->fBankChargeEQ; 	         // 电池组可充电量                 65       
			iRetVal = 2;
		}
		else if (67 == usRegAddr)
		{
			fVal = pBattBank->fBankDischargeEQ; 	     // 电池组可放电量	               67	      
			iRetVal = 2;
		}
		else if (69 == usRegAddr)
		{
			fVal = pBattBank->fBankSglChargeEQ;     	 // 电池组单次充电电量             69      
			iRetVal = 2;
		}
		else if (71 == usRegAddr)
		{
			fVal = pBattBank->fBankSglDischargeEQ; 	     // 电池组单次放电电量             71	      
			iRetVal = 2;
		}
		else if (73 == usRegAddr)
		{
			fVal = pBattBank->fBankChargeEQAdd; 	     // 电池组累计充电电量	           73	      
			iRetVal = 2;
		}
		else if (75 == usRegAddr)
		{
			fVal = pBattBank->fBankDischargeEQAdd;       // 电池组累计放电电量	           75 	      
			iRetVal = 2;
		}
		else if (77 == usRegAddr)
		{
			fVal = pBattBank->fTemp1;                    // 监测温度1                      77     
			iRetVal = 2;
		}
		else if (79 == usRegAddr)
		{
			fVal = pBattBank->fTemp2;                    // 监测温度2                      79     
			iRetVal = 2;
		}
		else if (81 == usRegAddr)
		{
			fVal = pBattBank->fTemp3;                    // 监测温度3                      81      
			iRetVal = 2;
		}
		else if (83 == usRegAddr)
		{
			fVal = pBattBank->fSglAvgVol;                // 单体电压平均值                 83      
			iRetVal = 2;
		}
		else if (85 == usRegAddr)
		{
			fVal = pBattBank->fSglMaxVol;                // 单电电压最大值                 85		      
			iRetVal = 2;
		}
		else if (87 == usRegAddr)
		{
			fVal = pBattBank->fSglMinVol; 	             // 单电电压最小值	               87	      
			iRetVal = 2;
		}
		else if (89 == usRegAddr)
		{
			fVal = pBattBank->fSglAvgTemp; 	             // 单体温度平均值                 89      
			iRetVal = 2;
		}
		else if (91 == usRegAddr)
		{
			fVal = pBattBank->fSglMaxTemp;               // 单电温度最大值	               91	 
			iRetVal = 2;
		}
		else if (93 == usRegAddr)
		{
			fVal = pBattBank->fSglMinTemp;               // 单电温度最小值	               93	      
			iRetVal = 2;
		}
		else if (95 == usRegAddr)
		{
			fVal = pBattBank->fSglAvgRes;                // 单体平均内阻	               95	      
			iRetVal = 2;
		}
		else if (97 == usRegAddr)
		{
			fVal = pBattBank->fSglMaxRes;                // 单体内阻最大值	               97		      
			iRetVal = 2;
		}
		else if (99 == usRegAddr)
		{
			fVal = pBattBank->fSglMinRes;                // 单体内阻最小值		           99      
			iRetVal = 2;
		}
		else if (101 == usRegAddr)
		{
			fVal = pBattBank->fSglAvgSoc; 	             // 单体SOC平均值                  101   
			iRetVal = 2;
		}
		else if (103 == usRegAddr)
		{
			fVal = pBattBank->fSglMaxSoc;                // 单体SOC最大值		           103      
			iRetVal = 2;
		}
		else if (105 == usRegAddr)
		{
			fVal = pBattBank->fSglMinSoc;                // 单体SOC最小值	               105      
			iRetVal = 2;
		}
		else if (107 == usRegAddr)
		{
			fVal = pBattBank->fSglAvgSoh;                // 单体SOH平均值                  107     
			iRetVal = 2;
		}
		else if (109 == usRegAddr)
		{
			fVal = pBattBank->fSglMaxSoh;                // 单体SOH最大值	               109	      
			iRetVal = 2;
		}
		else if (111 == usRegAddr)
		{
			fVal = pBattBank->fSglMinSoh;                // 单体SOH最小值	               111	    
			iRetVal = 2;
		}
		else if (113 == usRegAddr)
		{
			fVal = pBattBank->fBankAllowMaxChargePower;       // 电池组最大充电功率             113       
			iRetVal = 2;
		}
		else if (115 == usRegAddr)
		{
			fVal = pBattBank->fBankAllowMaxDischargePower;    // 电池组最大放电功率             115       
			iRetVal = 2;
		}
		else if (117 == usRegAddr)
		{
			fVal = pBattBank->fBankAllowMaxChargeCurrent;     // 电池组最大充电电流             117     
			iRetVal = 2;
		}
		else if (119 == usRegAddr)
		{
			fVal = pBattBank->fBankAllowMaxDischargeCurrent;  // 电池组最大放电电流             119      
			iRetVal = 2;
		}
		else if (usRegAddr >= 121 && usRegAddr <= 200) // 121 200
		{
			fVal = pBattBank->fBankTemp[(usRegAddr - 121) / 2]; 	      
			iRetVal = 2;
		}		
	}
	else if (usRegAddr >= 201 && usRegAddr <= 1000) // 单体电压                       201  ~ 1000
	{
		if (1 == usRegAddr % 2) // 正常的开始地址
		{
			fVal = pBattBank->fSglVol[((usRegAddr - 201) / 2)];
			iRetVal = 2;
		}
		else
		{
			iRetVal = -1;
		}		
	}

	else if (usRegAddr >= 1001 && usRegAddr <= 1800) // 单体温度                       1001 ~ 1800
	{
		if (1 == usRegAddr % 2) // 正常的开始地址
		{
			fVal = pBattBank->fSglTemp[((usRegAddr - 1001) / 2)];
			iRetVal = 2;
		}
		else
		{
			iRetVal = -1;
		}		
	}

	else if (usRegAddr >= 1801 && usRegAddr <= 2600) // 单体Soc                        1801 ~ 2600
	{
		if (1 == usRegAddr % 2) // 正常的开始地址
		{
			fVal = pBattBank->fSglSoc[((usRegAddr - 1801) / 2)];
			iRetVal = 2;
		}
		else
		{
			iRetVal = -1;
		}		
	}

	else if (usRegAddr >= 2601 && usRegAddr <= 3400) // 单体内阻                       2601 ~ 3400
	{
		if (1 == usRegAddr % 2) // 正常的开始地址
		{
			fVal = pBattBank->fSglRes[((usRegAddr - 2601) / 2)];
			iRetVal = 2;
		}
		else
		{
			iRetVal = -1;
		}		
	}

	else if (usRegAddr >= 3401 && usRegAddr <= 4200) // 单体Soh                        3401 ~ 4200
	{
		if (1 == usRegAddr % 2) // 正常的开始地址
		{
			fVal = pBattBank->fSglSoh[((usRegAddr - 3401) / 2)];
			iRetVal = 2;
		}
		else
		{
			iRetVal = -1;
		}		
	}	
	else
	{
		iRetVal = -1;
	}

	return iRetVal;
}

// 保持寄存器 - UINT16 类型
//  0 - 正确处理
// -1 - 参数错误
// -2 - 地址错误
int CModbusFactory::setAlarmHoldRegVal(quint16 usRegAddr, quint16 usVal, SAlarmParam* pAlarmParam, CBattBank* pBattBank, CBattStack* pBattStack)
{
	if(!pAlarmParam || !pBattBank || !pBattStack)
	{
		return -1;
	}

	int iRetVal = -999;
	float fTemp = 0;
	qint16 isVal = 0;

	if (0x3001 == usRegAddr)         // 单体电压预警上限值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3002 == usRegAddr)    // 单体电压预警上限回差值
	{
		fTemp = usVal * 0.001;
		if (qAbs(pAlarmParam->fSglVolUpLimitWarn - fTemp - pAlarmParam->fSglVolUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitWarnHC = pAlarmParam->fSglVolUpLimitWarn - fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3003 == usRegAddr)    // 单体电压预警下限值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3004 == usRegAddr)    // 单体电压预警下限值回差值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitWarn - pAlarmParam->fSglVolDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitWarnHC = fTemp - pAlarmParam->fSglVolDownLimitWarn;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3005 == usRegAddr)    // 组端电压预警上限值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3006 == usRegAddr)    // 组端电压预警上限值回差值
	{
		fTemp = usVal * 0.1;
		if (qAbs(pAlarmParam->fBankVolUpLimitWarn - fTemp - pAlarmParam->fBankVolUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitWarnHC = pAlarmParam->fBankVolUpLimitWarn - fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3007 == usRegAddr)    // 组端电压预警下限值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3008 == usRegAddr)    // 组端电压预警下限值回差值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolDownLimitWarn - pAlarmParam->fBankVolDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitWarnHC = fTemp - pAlarmParam->fBankVolDownLimitWarn;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3009 == usRegAddr)    // 充电电流预警上限值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeCurUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x300A == usRegAddr)    // 充电电流预警上限值回差值
	{
		fTemp = usVal * 0.1;
		if (qAbs(pAlarmParam->fChargeCurUpLimitWarn - fTemp - pAlarmParam->fChargeCurUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitWarnHC = pAlarmParam->fChargeCurUpLimitWarn - fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x300B == usRegAddr)    // 放电电流预警上限值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDischargeCurUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x300C == usRegAddr)    // 放电电流预警上限值回差值
	{
		fTemp = usVal * 0.1;
		if (qAbs(pAlarmParam->fDischargeCurUpLimitWarn - fTemp - pAlarmParam->fDischargeCurUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitWarnHC = pAlarmParam->fDischargeCurUpLimitWarn - fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x300D == usRegAddr)    // 充电温度预警上限值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x300E == usRegAddr)    // 充电温度预警上限值回差值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(pAlarmParam->fChargeSglTempUpLimitWarn - fTemp - pAlarmParam->fChargeSglTempUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitWarnHC = pAlarmParam->fChargeSglTempUpLimitWarn - fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x300F == usRegAddr)    // 充电温度预警下限值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3010 == usRegAddr)    // 充电温度预警下限值回差值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitWarn - pAlarmParam->fChargeSglTempDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitWarnHC = fTemp - pAlarmParam->fChargeSglTempDownLimitWarn;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3011 == usRegAddr)    // 组SOC
	{
		iRetVal = 0;
	}
	else if (0x3012 == usRegAddr)    // 组SOC
	{
		iRetVal = 0;
	}
	else if (0x3013 == usRegAddr)    // 极柱
	{
		iRetVal = 0;
	}
	else if (0x3014 == usRegAddr)    // 极柱
	{
		iRetVal = 0;
	}
	else if (0x3015 == usRegAddr)    // 绝缘预警下限值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fPosResDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fPosResDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}

		if (qAbs(fTemp - pAlarmParam->fNegResDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fNegResDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}

		iRetVal = 0;
	}
	else if (0x3016 == usRegAddr)    // 绝缘预警下限值回差值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fPosResDownLimitWarn - pAlarmParam->fPosResDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fPosResDownLimitWarnHC = fTemp - pAlarmParam->fPosResDownLimitWarn;
			pBattBank->usWarnParamModifyCount = 1;
		}

		if (qAbs(fTemp - pAlarmParam->fNegResDownLimitWarn - pAlarmParam->fNegResDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fNegResDownLimitWarnHC = fTemp - pAlarmParam->fNegResDownLimitWarn;
			pBattBank->usWarnParamModifyCount = 1;
		}
	
		iRetVal = 0;
	}
	else if (0x3017 == usRegAddr)    // 单体电压压差上限
	{
		iRetVal = 0;
	}
	else if (0x3018 == usRegAddr)    // 单体电压压差上限值回差值
	{		
		iRetVal = 0;
	}
	else if (0x3019 == usRegAddr)    // 组端压差预警上限值
	{
		iRetVal = 0;
	}
	else if (0x301A == usRegAddr)    // 组端压差预警上限值回差值
	{
		iRetVal = 0;
	}
	else if (0x301B == usRegAddr)    // 放电温度预警上限值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x301C == usRegAddr)    // 放电温度预警上限值回差值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(pAlarmParam->fDchargeSglTempUpLimitWarn - fTemp - pAlarmParam->fDchargeSglTempUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitWarnHC = pAlarmParam->fDchargeSglTempUpLimitWarn - fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x301D == usRegAddr)    // 放电温度预警下限值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x301E == usRegAddr)    // 放电温度预警下限值回差值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitWarn - pAlarmParam->fDchargeSglTempDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitWarnHC = fTemp - pAlarmParam->fDchargeSglTempDownLimitWarn;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x301F == usRegAddr)    // 单体温差预警上限值
	{
		iRetVal = 0;
	}
	else if (0x3020 == usRegAddr)    // 单体温差预警上限值回差值
	{
		iRetVal = 0;
	}
	else if (0x3021 == usRegAddr)    // 高压箱连接器温度
	{		
		iRetVal = 0;
	}
	else if (0x3022 == usRegAddr)    // 高压箱连接器温度回差值    
	{
		iRetVal = 0;
	}
	else if (0x3023 == usRegAddr)     // 单体电压告警上限值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3024 == usRegAddr)    // 单体电压告警上限回差值
	{
		fTemp = usVal * 0.001;
		if (qAbs(pAlarmParam->fSglVolUpLimitAlarm - fTemp - pAlarmParam->fSglVolUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitAlarmHC = pAlarmParam->fSglVolUpLimitAlarm - fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3025 == usRegAddr)    // 单体电压告警下限值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3026 == usRegAddr)    // 单体电压告警下限值回差值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitAlarm - pAlarmParam->fSglVolDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitAlarmHC = fTemp - pAlarmParam->fSglVolDownLimitAlarm;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3027 == usRegAddr)    // 组端电压告警上限值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3028 == usRegAddr)    // 组端电压告警上限值回差值
	{
		fTemp = usVal * 0.1;
		if (qAbs(pAlarmParam->fBankVolUpLimitAlarm - fTemp - pAlarmParam->fBankVolUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitAlarmHC = pAlarmParam->fBankVolUpLimitAlarm - fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3029 == usRegAddr)    // 组端电压告警下限值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x302A == usRegAddr)    // 组端电压告警下限值回差值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp -  pAlarmParam->fBankVolDownLimitAlarm - pAlarmParam->fBankVolDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitAlarmHC = fTemp - pAlarmParam->fBankVolDownLimitAlarm;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x302B == usRegAddr)    // 充电电流告警上限值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeCurUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x302C == usRegAddr)    // 充电电流告警上限值回差值
	{
		fTemp = usVal * 0.1;
		if (qAbs(pAlarmParam->fChargeCurUpLimitAlarm - fTemp - pAlarmParam->fChargeCurUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitAlarmHC = pAlarmParam->fChargeCurUpLimitAlarm - fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x302D == usRegAddr)    // 放电电流告警上限值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDischargeCurUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x302E == usRegAddr)    // 放电电流告警上限值回差值
	{
		fTemp = usVal * 0.1;
		if (qAbs(pAlarmParam->fDischargeCurUpLimitAlarm - fTemp - pAlarmParam->fDischargeCurUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitAlarmHC = pAlarmParam->fDischargeCurUpLimitAlarm - fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x302F == usRegAddr)    // 充电温度告警上限值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3030 == usRegAddr)    // 充电温度告警上限值回差值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(pAlarmParam->fChargeSglTempUpLimitAlarm - fTemp - pAlarmParam->fChargeSglTempUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitAlarmHC = pAlarmParam->fChargeSglTempUpLimitAlarm - fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3031 == usRegAddr)    // 充电温度告警下限值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3032 == usRegAddr)    // 充电温度告警下限值回差值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitAlarm - pAlarmParam->fChargeSglTempDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitAlarmHC = fTemp - pAlarmParam->fChargeSglTempDownLimitAlarm;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3033 == usRegAddr)    // 组SOC
	{
		iRetVal = 0;
	}
	else if (0x3034 == usRegAddr)    // 组SOC
	{
		iRetVal = 0;
	}
	else if (0x3035 == usRegAddr)    // 极柱
	{
		iRetVal = 0;
	}
	else if (0x3036 == usRegAddr)    // 极柱
	{
		iRetVal = 0;
	}
	else if (0x3037 == usRegAddr)    // 绝缘告警下限值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fPosResDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fPosResDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}

		if (qAbs(fTemp - pAlarmParam->fNegResDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fNegResDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}

		iRetVal = 0;
	}
	else if (0x3038 == usRegAddr)    // 绝缘告警下限值回差值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fPosResDownLimitAlarm - pAlarmParam->fPosResDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fPosResDownLimitAlarmHC = fTemp - pAlarmParam->fPosResDownLimitAlarm;
			pBattBank->usAlarmParamModifyCount = 1;
		}

		if (qAbs(fTemp - pAlarmParam->fNegResDownLimitAlarm - pAlarmParam->fNegResDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fNegResDownLimitAlarmHC = fTemp - pAlarmParam->fNegResDownLimitAlarm;
			pBattBank->usAlarmParamModifyCount = 1;
		}

		iRetVal = 0;
	}
	else if (0x3039 == usRegAddr)    // 单体电压压差上限
	{
		iRetVal = 0;
	}
	else if (0x303A == usRegAddr)    // 单体电压压差上限值回差值
	{		
		iRetVal = 0;
	}
	else if (0x303B == usRegAddr)    // 组端压差告警上限值
	{
		iRetVal = 0;
	}
	else if (0x303C == usRegAddr)    // 组端压差告警上限值回差值
	{
		iRetVal = 0;
	}
	else if (0x303D == usRegAddr)    // 放电温度告警上限值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x303E == usRegAddr)    // 放电温度告警上限值回差值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(pAlarmParam->fDchargeSglTempUpLimitAlarm - fTemp - pAlarmParam->fDchargeSglTempUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitAlarmHC = pAlarmParam->fDchargeSglTempUpLimitAlarm - fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x303F == usRegAddr)    // 放电温度告警下限值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3040 == usRegAddr)    // 放电温度告警下限值回差值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitAlarm - pAlarmParam->fDchargeSglTempDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitAlarmHC = fTemp - pAlarmParam->fDchargeSglTempDownLimitAlarm;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3041 == usRegAddr)    // 单体温差告警上限值
	{
		iRetVal = 0;
	}
	else if (0x3042 == usRegAddr)    // 单体温差告警上限值回差值
	{
		iRetVal = 0;
	}
	else if (0x3043 == usRegAddr)    // 高压箱连接器温度
	{		
		iRetVal = 0;
	}
	else if (0x3044 == usRegAddr)    // 高压箱连接器温度回差值    
	{
		iRetVal = 0;
	}
	else if (0x3045 == usRegAddr)         // 单体电压保护上限值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolUpLimitProt) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3046 == usRegAddr)    // 单体电压保护上限回差值
	{
		fTemp = usVal * 0.001;
		if (qAbs(pAlarmParam->fSglVolUpLimitProt - fTemp - pAlarmParam->fSglVolUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitProtHC = pAlarmParam->fSglVolUpLimitProt - fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3047 == usRegAddr)    // 单体电压保护下限值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitProt) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3048 == usRegAddr)    // 单体电压保护下限值回差值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitProt - pAlarmParam->fSglVolDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitProtHC = fTemp - pAlarmParam->fSglVolDownLimitProt;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3049 == usRegAddr)    // 组端电压保护上限值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolUpLimitProt) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x304A == usRegAddr)    // 组端电压保护上限值回差值
	{
		fTemp = usVal * 0.1;
		if (qAbs(pAlarmParam->fBankVolUpLimitProt - fTemp - pAlarmParam->fBankVolUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitProtHC = pAlarmParam->fBankVolUpLimitProt - fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x304B == usRegAddr)    // 组端电压保护下限值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolDownLimitProt) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x304C == usRegAddr)    // 组端电压保护下限值回差值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp -  pAlarmParam->fBankVolDownLimitProt - pAlarmParam->fBankVolDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitProtHC = fTemp - pAlarmParam->fBankVolDownLimitProt;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x304D == usRegAddr)    // 充电电流保护上限值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeCurUpLimitProt) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x304E == usRegAddr)    // 充电电流保护上限值回差值
	{
		fTemp = usVal * 0.1;
		if (qAbs(pAlarmParam->fChargeCurUpLimitProt - fTemp - pAlarmParam->fChargeCurUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitProtHC = pAlarmParam->fChargeCurUpLimitProt - fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x304F == usRegAddr)    // 放电电流保护上限值
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDischargeCurUpLimitProt) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3050 == usRegAddr)    // 放电电流保护上限值回差值
	{
		fTemp = usVal * 0.1;
		if (qAbs(pAlarmParam->fDischargeCurUpLimitProt - fTemp - pAlarmParam->fDischargeCurUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitProtHC = pAlarmParam->fDischargeCurUpLimitProt - fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3051 == usRegAddr)    // 充电温度保护上限值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempUpLimitProt) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3052 == usRegAddr)    // 充电温度保护上限值回差值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(pAlarmParam->fChargeSglTempUpLimitProt - fTemp - pAlarmParam->fChargeSglTempUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitProtHC = pAlarmParam->fChargeSglTempUpLimitProt - fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3053 == usRegAddr)    // 充电温度保护下限值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitProt) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3054 == usRegAddr)    // 充电温度保护下限值回差值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitProt - pAlarmParam->fChargeSglTempDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitProtHC = fTemp - pAlarmParam->fChargeSglTempDownLimitProt;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3055 == usRegAddr)    // 组SOC
	{
		iRetVal = 0;
	}
	else if (0x3056 == usRegAddr)    // 组SOC
	{
		iRetVal = 0;
	}
	else if (0x3057 == usRegAddr)    // 极柱
	{
		iRetVal = 0;
	}
	else if (0x3058 == usRegAddr)    // 极柱
	{
		iRetVal = 0;
	}
	else if (0x3059 == usRegAddr)    // 绝缘保护下限值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fPosResDownLimitProt) > 0.0001)
		{
			pAlarmParam->fPosResDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}

		if (qAbs(fTemp - pAlarmParam->fNegResDownLimitProt) > 0.0001)
		{
			pAlarmParam->fNegResDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}

		iRetVal = 0;
	}
	else if (0x305A == usRegAddr)    // 绝缘保护下限值回差值
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fPosResDownLimitProt - pAlarmParam->fPosResDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fPosResDownLimitProtHC = fTemp - pAlarmParam->fPosResDownLimitProt;
			pBattBank->usProtParamModifyCount = 1;
		}

		if (qAbs(fTemp - pAlarmParam->fNegResDownLimitProt - pAlarmParam->fNegResDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fNegResDownLimitProtHC = fTemp - pAlarmParam->fNegResDownLimitProt;
			pBattBank->usProtParamModifyCount = 1;
		}

		iRetVal = 0;
	}
	else if (0x305B == usRegAddr)    // 单体电压压差上限
	{
		iRetVal = 0;
	}
	else if (0x305C == usRegAddr)    // 单体电压压差上限值回差值
	{		
		iRetVal = 0;
	}
	else if (0x305D == usRegAddr)    // 组端压差保护上限值
	{
		iRetVal = 0;
	}
	else if (0x305E == usRegAddr)    // 组端压差保护上限值回差值
	{
		iRetVal = 0;
	}
	else if (0x305F == usRegAddr)    // 放电温度保护上限值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempUpLimitProt) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3060 == usRegAddr)    // 放电温度保护上限值回差值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(pAlarmParam->fDchargeSglTempUpLimitProt - fTemp - pAlarmParam->fDchargeSglTempUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitProtHC = pAlarmParam->fDchargeSglTempUpLimitProt - fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3061 == usRegAddr)    // 放电温度保护下限值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitProt) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3062 == usRegAddr)    // 放电温度保护下限值回差值
	{
		memcpy((char*)&isVal, (char*)&usVal, 2);
		fTemp = isVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitProt - pAlarmParam->fDchargeSglTempDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitProtHC = fTemp - pAlarmParam->fDchargeSglTempDownLimitProt;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if (0x3063 == usRegAddr)    // 单体温差保护上限值
	{
		iRetVal = 0;
	}
	else if (0x3064 == usRegAddr)    // 单体温差保护上限值回差值
	{
		iRetVal = 0;
	}
	else if (0x3065 == usRegAddr)    // 高压箱连接器温度
	{		
		iRetVal = 0;
	}
	else if (0x3066 == usRegAddr)    // 高压箱连接器温度回差值    
	{
		iRetVal = 0;
	}

	else if (0x3200 == usRegAddr)   // 1 - 启用   2 - 停用               0x3200
	{
		if (qAbs(pBattStack->fStackCur) < 5 && (1 == usVal || 2 == usVal))
		{
			pBattBank->usBankCfg = usVal;

			iRetVal = 0;
		}
		else
		{
			iRetVal = -3;
		}			
	}
	else if (0x3201 == usRegAddr)   // 允许切入  1 - 允许   0 - 不允许   0x3201
	{
		if (0 == usVal || 1 == usVal)
		{
			pBattBank->usAllowBankStepIn = usVal;

			iRetVal = 0;
		}
		else
		{
			iRetVal = -3;
		}	
	}
	else if (0x3202 == usRegAddr)   // 允许切出  1 - 允许   0 - 不允许   0x3202
	{
		if (0 == usVal || 1 == usVal)
		{
			pBattBank->usAllowBankQuitOut = usVal;

			iRetVal = 0;
		}
		else
		{
			iRetVal = -3;
		}	
	}

	else if (1 == usRegAddr)
	{
		if (0 == usVal || 1 == usVal || 2 == usVal)
		{
			if (pBattBank->usEMSContCtrlPos != usVal)
			{
				pBattBank->usEMSContCtrlPos = usVal;
				pBattBank->usEMSContModifyCountPos = 1;
			}

			iRetVal = 0;
		}
		else
		{
			iRetVal = -1;
		}		
	}
	else if (2 == usRegAddr)
	{
		if (0 == usVal || 1 == usVal || 2 == usVal)
		{
			if (pBattBank->usEMSContCtrlNeg != usVal)
			{
				pBattBank->usEMSContCtrlNeg = usVal;
				pBattBank->usEMSContModifyCountNeg = 1;
			}

			iRetVal = 0;
		}
		else
		{
			iRetVal = -1;
		}		
	}
	else if (101 == usRegAddr)        // 组端电压预警上限值       1	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(102 == usRegAddr)    // 组端电压预警下限值		2
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;	
		}
		iRetVal = 0;
	}
	else if(3 == usRegAddr)    // 充电电流预警上限值		3
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeCurUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;	
		}
		iRetVal = 0;
	}
	else if(4 == usRegAddr)    // 放电电流预警上限值    	4
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDischargeCurUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;	
		}
		iRetVal = 0;
	}
	else if(5 == usRegAddr)    // 单体电压预警上限值	    5
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(6 == usRegAddr)    // 单体电压预警下限值	    6	
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(7 == usRegAddr)    // 充电温度预警上限值	    7
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(8 == usRegAddr)    // 充电温度预警下限值	    8	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(9 == usRegAddr)    // 放电温度预警上限值	    9	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(10 == usRegAddr)    // 放电温度预警下限值	    10	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(11 == usRegAddr)    // 组SOC预警上限值	        11
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fBankSocUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(12 == usRegAddr)    // 组SOC预警下限值	        12	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fBankSocDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(13 == usRegAddr)    // 组端电压告警上限值    	13	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(14 == usRegAddr)    // 组端电压告警下限值	    14
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(15 == usRegAddr)    // 充电电流告警上限值	    15
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeCurUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(16 == usRegAddr)    // 放电电流告警上限值	    16	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDischargeCurUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(17 == usRegAddr)    // 单体电压告警上限值	    17
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(18 == usRegAddr)    // 单体电压告警下限值	    18	
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(19 == usRegAddr)    // 充电温度告警上限值	    19	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(20 == usRegAddr)    // 充电温度告警下限值	    20
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(21 == usRegAddr)    // 放电温度告警上限值	    21	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(22 == usRegAddr)    // 放电温度告警下限值	    22		
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(23 == usRegAddr)    // 组SOC告警上限值	        23	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fBankSocUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(24 == usRegAddr)    // 组SOC告警下限值	        24	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fBankSocDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(25 == usRegAddr)    // 组端电压保护上限值	    25	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolUpLimitProt) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(26 == usRegAddr)    // 组端电压保护下限值	    26
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolDownLimitProt) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(27 == usRegAddr)    // 充电电流保护上限值	    27
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeCurUpLimitProt) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(28 == usRegAddr)    // 放电电流保护上限值	    28	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDischargeCurUpLimitProt) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(29 == usRegAddr)    // 单体电压保护上限值	    29	
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolUpLimitProt) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(30 == usRegAddr)    // 单体电压保护下限值	    30	
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitProt) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(31 == usRegAddr)    // 充电温度保护上限值	    31	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempUpLimitProt) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(32 == usRegAddr)    // 充电温度保护下限值	    32	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitProt) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(33 == usRegAddr)    // 放电温度保护上限值	    33	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempUpLimitProt) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(34 == usRegAddr)    // 放电温度保护下限值	    34	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitProt) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(35 == usRegAddr)    // 组SOC保护上限值	        35	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocUpLimitProt) > 0.0001)
		{
			pAlarmParam->fBankSocUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(36 == usRegAddr)    // 组SOC保护下限值	        36	
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocDownLimitProt) > 0.0001)
		{
			pAlarmParam->fBankSocDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount = 1;
		}
		iRetVal = 0;
	}
	else if(37 == usRegAddr)    // 组端电压调整步长(系数) 	        37
	{	 	  
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fBankVolCoe) > 0.0001)
		{
			pBattBank->fBankVolCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
				
		iRetVal = 0;
	}
	else if(38 == usRegAddr)    // 充电电流调整步长(系数)	        38
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fChargeCurCoe) > 0.0001)
		{
			pBattBank->fChargeCurCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
		
		iRetVal = 0;
	}
	else if(39 == usRegAddr)    // 放电电流调整步长(系数)	        39	
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fDischargeCurCoe) > 0.0001)
		{
			pBattBank->fDischargeCurCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
		
		iRetVal = 0;
	}
	else if(40 == usRegAddr)    // 环境温度调整步长(系数)	        40	
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fEnvTempCoe) > 0.0001)
		{
			pBattBank->fEnvTempCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
		
		iRetVal = 0;
	}
	else if(41 == usRegAddr)    // 单体电压调整步长(系数)	        41
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fSglVolCoe) > 0.0001)
		{
			pBattBank->fSglVolCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
		
		iRetVal = 0;
	}
	else if(42 == usRegAddr)    // 单体温度调整步长(系数)	        42
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fSglTempCoe) > 0.0001)
		{
			pBattBank->fSglTempCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
		
		iRetVal = 0;
	}
	else if(43 == usRegAddr)    // SOC标定基准上限值调整步长(系数)  43	
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fBankSocRefUpLmtCoe) > 0.0001)
		{
			pBattBank->fBankSocRefUpLmtCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
		
		iRetVal = 0;
	}
	else if(44 == usRegAddr)    // SOC标定基准下限值调整步长(系数)   44	
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fBankSocRefDownLmtCoe) > 0.0001)
		{
			pBattBank->fBankSocRefDownLmtCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
		
		iRetVal = 0;
	}             
	else
	{
		iRetVal = 0;
	}	

	return iRetVal;	
}


// 保持寄存器 - UINT16 类型
//  0 - 正确处理
// -1 - 错误
// -2 - 地址错误
int CModbusFactory::addHoldRegVal2BufferUpdate(char* pData, quint16 usRegAddr, CBattStack* pBattStack)
{
	if(!pData || !pBattStack)
	{
		return -1;
	}

	int iRetVal = -999;	
	quint16 usTemp = 0;
	int iTemp = 0;

	if (0x0000 == usRegAddr)
	{
		usTemp = pBattStack->usUpdateCmd;
		iRetVal = 0;		
	}
	else if(0x0001 == usRegAddr)   
	{
		usTemp = pBattStack->usPrefLen;	
		iRetVal = 0;
	}	
	else if (usRegAddr >= 0x0002 && usRegAddr <= 0x0002 + 993 - 1)
	{
		usTemp = pBattStack->usPrefChar[usRegAddr - 0x0002];
		iRetVal = 0;
	}
	

	else if (0x03E3 == usRegAddr)
	{
		usTemp =  (quint16)(pBattStack->ulUpdateBaVers >> 48);
		iRetVal = 0;	
	}
	else if (0x03E4 == usRegAddr)
	{
		usTemp =  (quint16)(pBattStack->ulUpdateBaVers >> 32);
		iRetVal = 0;		
	}
	else if (0x03E5 == usRegAddr)
	{
		usTemp =  (quint16)(pBattStack->ulUpdateBaVers >> 16);
		iRetVal = 0;	
	}
	else if (0x03E6 == usRegAddr)
	{
		usTemp =  (quint16)(pBattStack->ulUpdateBaVers >> 0);
		iRetVal = 0;		
	}

	else if (usRegAddr >= 0x03E8 && usRegAddr <= 0x03E8 + 200 * 5 - 1)
	{
		iTemp = (usRegAddr - 0x03E8);
		if (0 == iTemp % 5)
		{
			usTemp = (quint16)(pBattStack->ulUpdateBcVers[(int)(iTemp / 5)] >> 48);
			iRetVal = 0;				
		}
		else if (1 == iTemp % 5)
		{
			usTemp = (quint16)(pBattStack->ulUpdateBcVers[(int)(iTemp / 5)]  >> 32);
			iRetVal = 0;				
		}
		else if (2 == iTemp % 5)
		{
			usTemp = (quint16)(pBattStack->ulUpdateBcVers[(int)(iTemp / 5)]  >> 16);
			iRetVal = 0;	
		}
		else if (3 == iTemp % 5)
		{		
			usTemp = (quint16)(pBattStack->ulUpdateBcVers[(int)(iTemp / 5)]  >> 0);
			iRetVal = 0;	
		}	
	}

	else if (usRegAddr >= 0x07D0 && usRegAddr <= 0x07D0 + 1600 * 5 - 1)
	{
		iTemp = (usRegAddr - 0x07D0);
		if (0 == iTemp % 5)
		{
			usTemp = (quint16)(pBattStack->ulUpdateBmuVers[(int)(iTemp / 5)] >> 48);
			iRetVal = 0;				
		}
		else if (1 == iTemp % 5)
		{
			usTemp = (quint16)(pBattStack->ulUpdateBmuVers[(int)(iTemp / 5)]  >> 32);
			iRetVal = 0;				
		}
		else if (2 == iTemp % 5)
		{
			usTemp = (quint16)(pBattStack->ulUpdateBmuVers[(int)(iTemp / 5)]  >> 16);
			iRetVal = 0;	
		}
		else if (3 == iTemp % 5)
		{		
			usTemp = (quint16)(pBattStack->ulUpdateBmuVers[(int)(iTemp / 5)]  >> 0);
			iRetVal = 0;	
		}	
	}

	else
	{
		iRetVal = -2;
	}

	if (0 == iRetVal)
	{
		addParam2Buffer(pData, usTemp);
	}

	return iRetVal;	
}

// 保持寄存器 - UINT16 类型
//  0 - 正确处理
// -1 - 参数错误
// -2 - 地址错误
// -3 - 设置值失败
int CModbusFactory::setUpdateHoldRegVal(quint16 usRegAddr, quint16 usVal, CBattStack* pBattStack)
{
	if(!pBattStack)
	{
		return -1;
	}

	int iRetVal = -999;
	quint32 uiTemp = 0;
	quint64 ulTemp = 0;
	int iTemp = 0;
	
	if (0x0000 == usRegAddr)
	{
		pBattStack->usUpdateCmd = usVal;
		iRetVal = 0;		
	}
	else if(0x0001 == usRegAddr)   
	{
		pBattStack->usPrefLen = usVal;
		iRetVal = 0;
	}	
	else if (usRegAddr >= 0x0002 && usRegAddr <= 0x0002 + 993 - 1)
	{
		pBattStack->usPrefChar[usRegAddr - 0x0002] = usVal;
		iRetVal = 0;
	}

	else if (0x03E3 == usRegAddr)
	{
		ulTemp = usVal;
		ulTemp = ulTemp << 48;
		ulTemp = ulTemp | (pBattStack->ulUpdateBaVers & 0x0000ffffffffffff);

		pBattStack->ulUpdateBaVers = ulTemp;
		iRetVal = 0;	
	}
	else if (0x03E4 == usRegAddr)
	{
		ulTemp = usVal;
		ulTemp = ulTemp << 32;
		ulTemp = ulTemp | (pBattStack->ulUpdateBaVers & 0xffff0000ffffffff);

		pBattStack->ulUpdateBaVers = ulTemp;
		iRetVal = 0;	
	}
	else if (0x03E5 == usRegAddr)
	{
		ulTemp = usVal;
		ulTemp = ulTemp << 16;
		ulTemp = ulTemp | (pBattStack->ulUpdateBaVers & 0xffffffff0000ffff);

		pBattStack->ulUpdateBaVers = ulTemp;
		iRetVal = 0;	
	}
	else if (0x03E6 == usRegAddr)
	{
		ulTemp = usVal;
		ulTemp = ulTemp | (pBattStack->ulUpdateBaVers & 0xffffffffffff0000);

		pBattStack->ulUpdateBaVers = ulTemp;
		iRetVal = 0;	
	}

	else if (usRegAddr >= 0x03E8 && usRegAddr <= 0x03E8 + 200 * 5 - 1)
	{
		iTemp = (usRegAddr - 0x03E8);
		if (0 == iTemp % 5)
		{
			ulTemp = usVal;
			ulTemp = ulTemp << 48;
			ulTemp = ulTemp | (pBattStack->ulUpdateBcVers[(int)(iTemp / 5)] & 0x0000ffffffffffff);

			pBattStack->ulUpdateBcVers[(int)(iTemp / 5)] = ulTemp;		
		}
		else if (1 == iTemp % 5)
		{
			ulTemp = usVal;
			ulTemp = ulTemp << 32;
			ulTemp = ulTemp | (pBattStack->ulUpdateBcVers[(int)(iTemp / 5)] & 0xffff0000ffffffff);

			pBattStack->ulUpdateBcVers[(int)(iTemp / 5)] = ulTemp;
		}
		else if (2 == iTemp % 5)
		{
			ulTemp = usVal;
			ulTemp = ulTemp << 16;
			ulTemp = ulTemp | (pBattStack->ulUpdateBcVers[(int)(iTemp / 5)] & 0xffffffff0000ffff);

			pBattStack->ulUpdateBcVers[(int)(iTemp / 5)] = ulTemp;
		}
		else if (3 == iTemp % 5)
		{
			ulTemp = usVal;
			ulTemp = ulTemp | (pBattStack->ulUpdateBcVers[(int)(iTemp / 5)] & 0xffffffffffff0000);

			pBattStack->ulUpdateBcVers[(int)(iTemp / 5)] = ulTemp;
		}		

		iRetVal = 0;		
	}

	else if (usRegAddr >= 0x07D0 && usRegAddr <= 0x07D0 + 1600 * 5 - 1)
	{
		iTemp = (usRegAddr - 0x07D0);
		if (0 == iTemp % 5)
		{
			ulTemp = usVal;
			ulTemp = ulTemp << 48;
			ulTemp = ulTemp | (pBattStack->ulUpdateBmuVers[(int)(iTemp / 5)] & 0x0000ffffffffffff);

			pBattStack->ulUpdateBmuVers[(int)(iTemp / 5)] = ulTemp;		
		}
		else if (1 == iTemp % 5)
		{
			ulTemp = usVal;
			ulTemp = ulTemp << 32;
			ulTemp = ulTemp | (pBattStack->ulUpdateBmuVers[(int)(iTemp / 5)] & 0xffff0000ffffffff);

			pBattStack->ulUpdateBmuVers[(int)(iTemp / 5)] = ulTemp;
		}
		else if (2 == iTemp % 5)
		{
			ulTemp = usVal;
			ulTemp = ulTemp << 16;
			ulTemp = ulTemp | (pBattStack->ulUpdateBmuVers[(int)(iTemp / 5)] & 0xffffffff0000ffff);

			pBattStack->ulUpdateBmuVers[(int)(iTemp / 5)] = ulTemp;
		}
		else if (3 == iTemp % 5)
		{
			ulTemp = usVal;
			ulTemp = ulTemp | (pBattStack->ulUpdateBmuVers[(int)(iTemp / 5)] & 0xffffffffffff0000);

			pBattStack->ulUpdateBmuVers[(int)(iTemp / 5)] = ulTemp;
		}		

		iRetVal = 0;
	}

	return iRetVal;	
}

// 保持寄存器 - UINT16 类型
//  0 - 正确处理
// -1 - 参数错误
// -2 - 地址错误
// -3 - 设置值失败
int CModbusFactory::setStackHoldRegVal(quint16 usRegAddr, quint16 usVal, CBattStack* pBattStack)
{
	if(!pBattStack)
	{
		return -1;
	}

	int iRetVal = -999;
	bool bNeedSetTime = false;

	if(1 == usRegAddr)    // 并网开关 0x1:启动(Start Connection);     1      
	{
		if (0 == pBattStack->usStartConn && 1 == usVal)
		{
			pBattStack->usStartConn = 1;
			pBattStack->usConnState = 0; // 启动

			iRetVal = 0;
		}		
		else if (1 == pBattStack->usStartConn && 2 == usVal)
		{			
			pBattStack->usStartConn = 0;
			//pBattStack->usConnState = 0; // 启动		
			iRetVal = 0;
		}
		else
		{
			//iRetVal = -3;
			iRetVal = 0; // 便于EMS统一来设置 0x10 命令
		}			
	}
	else if (2 == usRegAddr) // EMS设置心跳值                        	 2
	{
		++pBattStack->usEMSHeartbeat;
		iRetVal = 0;			
	}
	
	else if (3 == usRegAddr) // 年	                     2
	{
		if (usVal <= 99 ) // 0 ~ 99
		{
			pBattStack->usYear = usVal;

			bNeedSetTime = true;
			iRetVal = 0;
		}
		else
		{
			//iRetVal = -3;
			iRetVal = 0; // 便于EMS统一来设置 0x10 命令
		}		
	}
	else if (4 == usRegAddr) // 月	                     3
	{
		if (usVal >= 1 && usVal <= 12) // 1 ~ 12
		{
			pBattStack->usMonth = usVal;

			bNeedSetTime = true;
			iRetVal = 0;
		}
		else
		{
			//iRetVal = -3;
			iRetVal = 0; // 便于EMS统一来设置 0x10 命令
		}		
	}
	else if (5 == usRegAddr) // 日	                     4
	{
		if (usVal >= 1 && usVal <= 31) // 1 ~ 31
		{
			pBattStack->usDay = usVal;

			bNeedSetTime = true;
			iRetVal = 0;		
		}
		else
		{
			//iRetVal = -3;
			iRetVal = 0; // 便于EMS统一来设置 0x10 命令
		}		
	}
	else if (6 == usRegAddr) // 时	                     5
	{
		if (usVal <= 23) // 0 ~ 23
		{
			pBattStack->usHour = usVal;

			bNeedSetTime = true;
			iRetVal = 0;		
		}
		else
		{
			//iRetVal = -3;
			iRetVal = 0; // 便于EMS统一来设置 0x10 命令
		}	
	}
	else if (7 == usRegAddr) // 分	                     6
	{
		if (usVal <= 59) // 0 ~ 59
		{
			pBattStack->usMin = usVal;

			bNeedSetTime = true;
			iRetVal = 0;		
		}
		else
		{
			//iRetVal = -3;
			iRetVal = 0; // 便于EMS统一来设置 0x10 命令
		}	
	}
	else if (8 == usRegAddr) // 秒	                    8
	{
		if (usVal <= 59) // 0 ~ 59
		{
			pBattStack->usSec = usVal;

			bNeedSetTime = true;
			iRetVal = 0;		
		}
		else
		{
			//iRetVal = -3;
			iRetVal = 0; // 便于EMS统一来设置 0x10 命令
		}			
	}
	else if (9 == usRegAddr) // reboot                 9
	{
		if(usVal > 0)
		{
			pBattStack->usReboot = 1;
			iRetVal = 0; 
		}	
		iRetVal = 0; 
	}
	
	if (bNeedSetTime) // 设置日期确认	         
	{	
		if (pBattStack->usYear <= 99 && pBattStack->usMonth >= 1 && pBattStack->usMonth <= 12 &&
			pBattStack->usDay >= 1 && pBattStack->usDay <= 31 && pBattStack->usHour <= 23 && pBattStack->usMin <= 59 && pBattStack->usSec <= 59)
		{
#ifdef XNLINUX
			// set system datetime
			struct tm nowtime;  
			time_t t;  

			nowtime.tm_sec = pBattStack->usSec;         /* Seconds.[0-60](1 leap second)*/  
			nowtime.tm_min = pBattStack->usMin;         /* Minutes.[0-59] */   
			nowtime.tm_hour = pBattStack->usHour;       /* Hours. [0-23] */    
			nowtime.tm_mday = pBattStack->usDay;        /* Day.[1-31]  */    
			nowtime.tm_mon = pBattStack->usMonth - 1;   /* Month.[0-11] */  
			nowtime.tm_year = pBattStack->usYear + 2000 - 1900;/* Year- 1900. */    
			nowtime.tm_isdst = -1;                      /* DST.[-1/0/1]*/    

			t=mktime(&nowtime);    
			ctime(&t);    

			// set to COMS
			iRetVal = 0;
			if (0 == fork())     // 子进程号固定为0
			{
				execlp("/sbin/hwclock", "hwclock", "-w", (char*)0);
				/*if (execlp("/sbin/hwclock", "hwclock", "-w", (char*)0) < 0)
				{
					iRetVal = -4;
				}	*/			
			}				
			wait(NULL);          // 等待子进程结束
#endif
		}		
	}
	
	return iRetVal;	
}

// 保持寄存器 - UINT16 类型
//  0 - 正确处理
// -1 - 错误
// -2 - 地址错误
int CModbusFactory::addHoldRegVal2BufferAlarm(char* pData, quint16 usRegAddr, SAlarmParam* pAlarmParam, CBattBank* pBattBank)
{
	if(!pData || !pAlarmParam || !pBattBank)
	{
		return -1;
	}

	int iRetVal = -999;
	quint16 usTemp = 0;
	qint16 isTemp = 0;

	if (0x3001 == usRegAddr || 0x3101 == usRegAddr)         // 单体电压预警上限值
	{
		usTemp = (quint16)(pAlarmParam->fSglVolUpLimitWarn * 1000);
		iRetVal = 0;
	}
	else if (0x3002 == usRegAddr || 0x3102 == usRegAddr)    // 单体电压预警上限回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fSglVolUpLimitWarn - pAlarmParam->fSglVolUpLimitWarnHC) * 1000);
		iRetVal = 0;		
	}
	else if (0x3003 == usRegAddr || 0x3103 == usRegAddr)    // 单体电压预警下限值
	{
		usTemp = (quint16)(pAlarmParam->fSglVolDownLimitWarn * 1000);
		iRetVal = 0;	
	}
	else if (0x3004 == usRegAddr || 0x3104 == usRegAddr)    // 单体电压预警下限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fSglVolDownLimitWarn + pAlarmParam->fSglVolDownLimitWarnHC) * 1000);
		iRetVal = 0;		
	}
	else if (0x3005 == usRegAddr || 0x3105 == usRegAddr)    // 组端电压预警上限值
	{
		usTemp = (quint16)(pAlarmParam->fBankVolUpLimitWarn * 10);
		iRetVal = 0;		
	}
	else if (0x3006 == usRegAddr || 0x3106 == usRegAddr)    // 组端电压预警上限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fBankVolUpLimitWarn - pAlarmParam->fBankVolUpLimitWarnHC) * 10);
		iRetVal = 0;	
	}
	else if (0x3007 == usRegAddr || 0x3107 == usRegAddr)    // 组端电压预警下限值
	{
		usTemp = (quint16)(pAlarmParam->fBankVolDownLimitWarn * 10);
		iRetVal = 0;		
	}
	else if (0x3008 == usRegAddr || 0x3108 == usRegAddr)    // 组端电压预警下限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fBankVolDownLimitWarn + pAlarmParam->fBankVolDownLimitWarnHC) * 10);
		iRetVal = 0;		
	}
	else if (0x3009 == usRegAddr || 0x3109 == usRegAddr)    // 充电电流预警上限值
	{
		usTemp = (quint16)(pAlarmParam->fChargeCurUpLimitWarn * 10);
		iRetVal = 0;
	}
	else if (0x300A == usRegAddr || 0x310A == usRegAddr)    // 充电电流预警上限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fChargeCurUpLimitWarn - pAlarmParam->fChargeCurUpLimitWarnHC) * 10);
		iRetVal = 0;	
	}
	else if (0x300B == usRegAddr || 0x310B == usRegAddr)    // 放电电流预警上限值
	{
		usTemp = (quint16)(pAlarmParam->fDischargeCurUpLimitWarn * 10);
		iRetVal = 0;
	}
	else if (0x300C == usRegAddr || 0x310C == usRegAddr)    // 放电电流预警上限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fDischargeCurUpLimitWarn - pAlarmParam->fDischargeCurUpLimitWarnHC) * 10);
		iRetVal = 0;	
	}
	else if (0x300D == usRegAddr || 0x310D == usRegAddr)    // 充电温度预警上限值
	{	
		isTemp = (qint16)(pAlarmParam->fChargeSglTempUpLimitWarn * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x300E == usRegAddr || 0x310E == usRegAddr)    // 充电温度预警上限值回差值
	{
		isTemp = (qint16)(qAbs(pAlarmParam->fChargeSglTempUpLimitWarn - pAlarmParam->fChargeSglTempUpLimitWarnHC) * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x300F == usRegAddr || 0x310F == usRegAddr)    // 充电温度预警下限值
	{
		isTemp = (qint16)(pAlarmParam->fChargeSglTempDownLimitWarn * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x3010 == usRegAddr || 0x3110 == usRegAddr)    // 充电温度预警下限值回差值
	{
		isTemp = (qint16)(qAbs(pAlarmParam->fChargeSglTempDownLimitWarn + pAlarmParam->fChargeSglTempDownLimitWarnHC) * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x3011 == usRegAddr || 0x3111 == usRegAddr)    // 组SOC
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3012 == usRegAddr || 0x3112 == usRegAddr)    // 组SOC
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3013 == usRegAddr || 0x3113 == usRegAddr)    // 极柱
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3014 == usRegAddr || 0x3114 == usRegAddr)    // 极柱
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3015 == usRegAddr || 0x3115 == usRegAddr)    // 绝缘预警下限值
	{
		usTemp = (quint16)(pAlarmParam->fPosResDownLimitWarn * 1000);
		iRetVal = 0;
	}
	else if (0x3016 == usRegAddr || 0x3116 == usRegAddr)    // 绝缘预警下限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fPosResDownLimitWarn + pAlarmParam->fPosResDownLimitWarnHC) * 1000);
		iRetVal = 0;	
	}
	else if (0x3017 == usRegAddr || 0x3117 == usRegAddr)    // 单体电压压差上限
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3018 == usRegAddr || 0x3118 == usRegAddr)    // 单体电压压差上限值回差值
	{		
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3019 == usRegAddr || 0x3119 == usRegAddr)    // 组端压差预警上限值
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x301A == usRegAddr || 0x311A == usRegAddr)    // 组端压差预警上限值回差值
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x301B == usRegAddr || 0x311B == usRegAddr)    // 放电温度预警上限值
	{
		isTemp = (qint16)(pAlarmParam->fDchargeSglTempUpLimitWarn * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;	
	}
	else if (0x301C == usRegAddr || 0x311C == usRegAddr)    // 放电温度预警上限值回差值
	{
		isTemp = (qint16)(qAbs(pAlarmParam->fDchargeSglTempUpLimitWarn - pAlarmParam->fDchargeSglTempUpLimitWarnHC) * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x301D == usRegAddr || 0x311D == usRegAddr)    // 放电温度预警下限值
	{
		isTemp = (qint16)(pAlarmParam->fDchargeSglTempDownLimitWarn * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x301E == usRegAddr || 0x311E == usRegAddr)    // 放电温度预警下限值回差值
	{
		isTemp = (qint16)(qAbs(pAlarmParam->fDchargeSglTempDownLimitWarn + pAlarmParam->fDchargeSglTempDownLimitWarnHC) * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;	
	}
	else if (0x301F == usRegAddr || 0x311F == usRegAddr)    // 单体温差预警上限值
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3020 == usRegAddr || 0x3120 == usRegAddr)    // 单体温差预警上限值回差值
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3021 == usRegAddr || 0x3121 == usRegAddr)    // 高压箱连接器温度
	{		
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3022 == usRegAddr || 0x3122 == usRegAddr)    // 高压箱连接器温度回差值    
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3023 == usRegAddr || 0x3123 == usRegAddr)    // 单体电压告警上限值
	{
		usTemp = (quint16)(pAlarmParam->fSglVolUpLimitAlarm * 1000);
		iRetVal = 0;
	}
	else if (0x3024 == usRegAddr || 0x3124 == usRegAddr)    // 单体电压告警上限回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fSglVolUpLimitAlarm - pAlarmParam->fSglVolUpLimitAlarmHC) * 1000);
		iRetVal = 0;		
	}
	else if (0x3025 == usRegAddr || 0x3125 == usRegAddr)    // 单体电压告警下限值
	{
		usTemp = (quint16)(pAlarmParam->fSglVolDownLimitAlarm * 1000);
		iRetVal = 0;	
	}
	else if (0x3026 == usRegAddr || 0x3126 == usRegAddr)    // 单体电压告警下限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fSglVolDownLimitAlarm + pAlarmParam->fSglVolDownLimitAlarmHC) * 1000);
		iRetVal = 0;		
	}
	else if (0x3027 == usRegAddr || 0x3127 == usRegAddr)    // 组端电压告警上限值
	{
		usTemp = (quint16)(pAlarmParam->fBankVolUpLimitAlarm * 10);
		iRetVal = 0;		
	}
	else if (0x3028 == usRegAddr || 0x3128 == usRegAddr)    // 组端电压告警上限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fBankVolUpLimitAlarm - pAlarmParam->fBankVolUpLimitAlarmHC) * 10);
		iRetVal = 0;	
	}
	else if (0x3029 == usRegAddr || 0x3129 == usRegAddr)    // 组端电压告警下限值
	{
		usTemp = (quint16)(pAlarmParam->fBankVolDownLimitAlarm * 10);
		iRetVal = 0;		
	}
	else if (0x302A == usRegAddr || 0x312A == usRegAddr)    // 组端电压告警下限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fBankVolDownLimitAlarm + pAlarmParam->fBankVolDownLimitAlarmHC) * 10);
		iRetVal = 0;		
	}
	else if (0x302B == usRegAddr || 0x312B == usRegAddr)    // 充电电流告警上限值
	{
		usTemp = (quint16)(pAlarmParam->fChargeCurUpLimitAlarm * 10);
		iRetVal = 0;
	}
	else if (0x302C == usRegAddr || 0x312C == usRegAddr)    // 充电电流告警上限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fChargeCurUpLimitAlarm - pAlarmParam->fChargeCurUpLimitAlarmHC) * 10);
		iRetVal = 0;	
	}
	else if (0x302D == usRegAddr || 0x312D == usRegAddr)    // 放电电流告警上限值
	{
		usTemp = (quint16)(pAlarmParam->fDischargeCurUpLimitAlarm * 10);
		iRetVal = 0;
	}
	else if (0x302E == usRegAddr || 0x312E == usRegAddr)    // 放电电流告警上限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fDischargeCurUpLimitAlarm - pAlarmParam->fDischargeCurUpLimitAlarmHC) * 10);
		iRetVal = 0;	
	}
	else if (0x302F == usRegAddr || 0x312F == usRegAddr)    // 充电温度告警上限值
	{
		isTemp = (qint16)(pAlarmParam->fChargeSglTempUpLimitAlarm * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x3030 == usRegAddr || 0x3130 == usRegAddr)    // 充电温度告警上限值回差值
	{
		isTemp = (qint16)(qAbs(pAlarmParam->fChargeSglTempUpLimitAlarm - pAlarmParam->fChargeSglTempUpLimitAlarmHC) * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x3031 == usRegAddr || 0x3131 == usRegAddr)    // 充电温度告警下限值
	{
		isTemp = (qint16)(pAlarmParam->fChargeSglTempDownLimitAlarm * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x3032 == usRegAddr || 0x3132 == usRegAddr)    // 充电温度告警下限值回差值
	{
		isTemp = (qint16)(qAbs(pAlarmParam->fChargeSglTempDownLimitAlarm + pAlarmParam->fChargeSglTempDownLimitAlarmHC) * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x3033 == usRegAddr || 0x3133 == usRegAddr)    // 组SOC
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3034 == usRegAddr || 0x3134 == usRegAddr)    // 组SOC
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3035 == usRegAddr || 0x3135 == usRegAddr)    // 极柱
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3036 == usRegAddr || 0x3136 == usRegAddr)    // 极柱
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3037 == usRegAddr || 0x3137 == usRegAddr)    // 绝缘告警下限值
	{
		usTemp = (quint16)(pAlarmParam->fPosResDownLimitAlarm * 1000);
		iRetVal = 0;
	}
	else if (0x3038 == usRegAddr || 0x3138 == usRegAddr)    // 绝缘告警下限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fPosResDownLimitAlarm + pAlarmParam->fPosResDownLimitAlarmHC) * 1000);
		iRetVal = 0;	
	}
	else if (0x3039 == usRegAddr || 0x3139 == usRegAddr)    // 单体电压压差上限
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x303A == usRegAddr || 0x313A == usRegAddr)    // 单体电压压差上限值回差值
	{		
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x303B == usRegAddr || 0x313B == usRegAddr)    // 组端压差告警上限值
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x303C == usRegAddr || 0x313C == usRegAddr)    // 组端压差告警上限值回差值
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x303D == usRegAddr || 0x313D == usRegAddr)    // 放电温度告警上限值
	{
		isTemp = (qint16)(pAlarmParam->fDchargeSglTempUpLimitAlarm * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;	
	}
	else if (0x303E == usRegAddr || 0x313E == usRegAddr)    // 放电温度告警上限值回差值
	{
		isTemp = (qint16)(qAbs(pAlarmParam->fDchargeSglTempUpLimitAlarm - pAlarmParam->fDchargeSglTempUpLimitAlarmHC) * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x303F == usRegAddr || 0x313F == usRegAddr)    // 放电温度告警下限值
	{
		isTemp = (qint16)(pAlarmParam->fDchargeSglTempDownLimitAlarm * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);	
		iRetVal = 0;		
	}
	else if (0x3040 == usRegAddr || 0x3140 == usRegAddr)    // 放电温度告警下限值回差值
	{
		isTemp = (qint16)(qAbs(pAlarmParam->fDchargeSglTempDownLimitAlarm + pAlarmParam->fDchargeSglTempDownLimitAlarmHC) * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;	
	}
	else if (0x3041 == usRegAddr || 0x3141 == usRegAddr)    // 单体温差告警上限值
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3042 == usRegAddr || 0x3142 == usRegAddr)    // 单体温差告警上限值回差值
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3043 == usRegAddr || 0x3143 == usRegAddr)    // 高压箱连接器温度
	{		
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3044 == usRegAddr || 0x3144 == usRegAddr)    // 高压箱连接器温度回差值    
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3045 == usRegAddr || 0x3145 == usRegAddr)         // 单体电压保护上限值
	{
		usTemp = (quint16)(pAlarmParam->fSglVolUpLimitProt * 1000);
		iRetVal = 0;
	}
	else if (0x3046 == usRegAddr || 0x3146 == usRegAddr)    // 单体电压保护上限回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fSglVolUpLimitProt - pAlarmParam->fSglVolUpLimitProtHC) * 1000);
		iRetVal = 0;		
	}
	else if (0x3047 == usRegAddr || 0x3147 == usRegAddr)    // 单体电压保护下限值
	{
		usTemp = (quint16)(pAlarmParam->fSglVolDownLimitProt * 1000);
		iRetVal = 0;	
	}
	else if (0x3048 == usRegAddr || 0x3148 == usRegAddr)    // 单体电压保护下限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fSglVolDownLimitProt + pAlarmParam->fSglVolDownLimitProtHC) * 1000);
		iRetVal = 0;		
	}
	else if (0x3049 == usRegAddr || 0x3149 == usRegAddr)    // 组端电压保护上限值
	{
		usTemp = (quint16)(pAlarmParam->fBankVolUpLimitProt * 10);
		iRetVal = 0;		
	}
	else if (0x304A == usRegAddr || 0x314A == usRegAddr)    // 组端电压保护上限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fBankVolUpLimitProt - pAlarmParam->fBankVolUpLimitProtHC) * 10);
		iRetVal = 0;	
	}
	else if (0x304B == usRegAddr || 0x314B == usRegAddr)    // 组端电压保护下限值
	{
		usTemp = (quint16)(pAlarmParam->fBankVolDownLimitProt * 10);
		iRetVal = 0;		
	}
	else if (0x304C == usRegAddr || 0x314C == usRegAddr)    // 组端电压保护下限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fBankVolDownLimitProt + pAlarmParam->fBankVolDownLimitProtHC) * 10);
		iRetVal = 0;		
	}
	else if (0x304D == usRegAddr || 0x314D == usRegAddr)    // 充电电流保护上限值
	{
		usTemp = (quint16)(pAlarmParam->fChargeCurUpLimitProt * 10);
		iRetVal = 0;
	}
	else if (0x304E == usRegAddr || 0x314E == usRegAddr)    // 充电电流保护上限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fChargeCurUpLimitProt - pAlarmParam->fChargeCurUpLimitProtHC) * 10);
		iRetVal = 0;	
	}
	else if (0x304F == usRegAddr || 0x314F == usRegAddr)    // 放电电流保护上限值
	{
		usTemp = (quint16)(pAlarmParam->fDischargeCurUpLimitProt * 10);
		iRetVal = 0;
	}
	else if (0x3050 == usRegAddr || 0x3150 == usRegAddr)    // 放电电流保护上限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fDischargeCurUpLimitProt - pAlarmParam->fDischargeCurUpLimitProtHC) * 10);
		iRetVal = 0;	
	}
	else if (0x3051 == usRegAddr || 0x3151 == usRegAddr)    // 充电温度保护上限值
	{
		isTemp = (qint16)(pAlarmParam->fChargeSglTempUpLimitProt * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x3052 == usRegAddr || 0x3152 == usRegAddr)    // 充电温度保护上限值回差值
	{
		isTemp = (qint16)(qAbs(pAlarmParam->fChargeSglTempUpLimitProt - pAlarmParam->fChargeSglTempUpLimitProtHC) * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x3053 == usRegAddr || 0x3153 == usRegAddr)    // 充电温度保护下限值
	{
		isTemp = (qint16)(pAlarmParam->fChargeSglTempDownLimitProt * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x3054 == usRegAddr || 0x3154 == usRegAddr)    // 充电温度保护下限值回差值
	{
		isTemp = (qint16)(qAbs(pAlarmParam->fChargeSglTempDownLimitProt + pAlarmParam->fChargeSglTempDownLimitProtHC) * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x3055 == usRegAddr || 0x3155 == usRegAddr)    // 组SOC
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3056 == usRegAddr || 0x3156 == usRegAddr)    // 组SOC
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3057 == usRegAddr || 0x3157 == usRegAddr)    // 极柱
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3058 == usRegAddr || 0x3158 == usRegAddr)    // 极柱
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3059 == usRegAddr || 0x3159 == usRegAddr)    // 绝缘保护下限值
	{
		usTemp = (quint16)(pAlarmParam->fPosResDownLimitProt * 1000);
		iRetVal = 0;
	}
	else if (0x305A == usRegAddr || 0x315A == usRegAddr)    // 绝缘保护下限值回差值
	{
		usTemp = (quint16)(qAbs(pAlarmParam->fPosResDownLimitProt + pAlarmParam->fPosResDownLimitProtHC) * 1000);
		iRetVal = 0;	
	}
	else if (0x305B == usRegAddr || 0x315B == usRegAddr)    // 单体电压压差上限
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x305C == usRegAddr || 0x315C == usRegAddr)    // 单体电压压差上限值回差值
	{		
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x305D == usRegAddr || 0x315D == usRegAddr)    // 组端压差保护上限值
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x305E == usRegAddr || 0x315E == usRegAddr)    // 组端压差保护上限值回差值
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x305F == usRegAddr || 0x315F == usRegAddr)    // 放电温度保护上限值
	{
		isTemp = (qint16)(pAlarmParam->fDchargeSglTempUpLimitProt * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;	
	}
	else if (0x3060 == usRegAddr || 0x3160 == usRegAddr)    // 放电温度保护上限值回差值
	{
		isTemp = (qint16)(qAbs(pAlarmParam->fDchargeSglTempUpLimitProt - pAlarmParam->fDchargeSglTempUpLimitProtHC) * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);	
		iRetVal = 0;		
	}
	else if (0x3061 == usRegAddr || 0x3161 == usRegAddr)    // 放电温度保护下限值
	{
		isTemp = (qint16)(pAlarmParam->fDchargeSglTempDownLimitProt * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;		
	}
	else if (0x3062 == usRegAddr || 0x3162 == usRegAddr)    // 放电温度保护下限值回差值
	{
		isTemp = (qint16)(qAbs(pAlarmParam->fDchargeSglTempDownLimitProt + pAlarmParam->fDchargeSglTempDownLimitProtHC) * 10);
		memcpy((char*)&usTemp, (char*)&isTemp, 2);
		iRetVal = 0;	
	}
	else if (0x3063 == usRegAddr || 0x3163 == usRegAddr)    // 单体温差保护上限值
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3064 == usRegAddr || 0x3164 == usRegAddr)    // 单体温差保护上限值回差值
	{
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3065 == usRegAddr || 0x3165 == usRegAddr)    // 高压箱连接器温度
	{		
		usTemp = 0;
		iRetVal = 0;
	}
	else if (0x3066 == usRegAddr || 0x3166 == usRegAddr)    // 高压箱连接器温度回差值    
	{
		usTemp = 0;
		iRetVal = 0;
	}
	
	else if (0x3200 == usRegAddr) 
	{
		usTemp = pBattBank->usBankCfg;		
		iRetVal = 0;
	}
	else if (0x3201 == usRegAddr) 
	{
		usTemp = pBattBank->usAllowBankStepIn;		
		iRetVal = 0;
	}
	else if (0x3202 == usRegAddr) 
	{
		usTemp = pBattBank->usAllowBankQuitOut;		
		iRetVal = 0;
	}

	else if (1 == usRegAddr) 
	{
		usTemp = pBattBank->usEMSContCtrlPos;		
		iRetVal = 0;
	}
	else if (2 == usRegAddr)
	{
		usTemp = pBattBank->usEMSContCtrlNeg;		
		iRetVal = 0;
	}
	else if (101 == usRegAddr)        // 组端电压预警上限值       1	
	{
		usTemp = (quint16)(pAlarmParam->fBankVolUpLimitWarn * 10);
		iRetVal = 0;
	}
	else if(102 == usRegAddr)    // 组端电压预警下限值		2
	{
		usTemp = (quint16)(pAlarmParam->fBankVolDownLimitWarn * 10);
		iRetVal = 0;
	}
	else if(3 == usRegAddr)    // 充电电流预警上限值		3
	{
		usTemp = (quint16)(pAlarmParam->fChargeCurUpLimitWarn * 10);
		iRetVal = 0;
	}
	else if(4 == usRegAddr)    // 放电电流预警上限值    	4
	{
		usTemp = (quint16)(pAlarmParam->fDischargeCurUpLimitWarn * 10);
		iRetVal = 0;
	}
	else if(5 == usRegAddr)    // 单体电压预警上限值	    5
	{
		usTemp = (quint16)(pAlarmParam->fSglVolUpLimitWarn * 1000);
		iRetVal = 0;
	}
	else if(6 == usRegAddr)    // 单体电压预警下限值	    6	
	{
		usTemp = (quint16)(pAlarmParam->fSglVolDownLimitWarn * 1000);
		iRetVal = 0;
	}
	else if(7 == usRegAddr)    // 充电温度预警上限值	    7
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempUpLimitWarn * 10);
		iRetVal = 0;
	}
	else if(8 == usRegAddr)    // 充电温度预警下限值	    8	
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempDownLimitWarn * 10);
		iRetVal = 0;
	}
	else if(9 == usRegAddr)    // 放电温度预警上限值	    9	
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempUpLimitWarn * 10);
		iRetVal = 0;
	}
	else if(10 == usRegAddr)    // 放电温度预警下限值	    10	
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempDownLimitWarn * 10);
		iRetVal = 0;
	}
	else if(11 == usRegAddr)    // 组SOC预警上限值	        11
	{
		usTemp = (quint16)(pAlarmParam->fBankSocUpLimitWarn * 10);  
		iRetVal = 0;
	}
	else if(12 == usRegAddr)    // 组SOC预警下限值	        12	
	{
		usTemp = (quint16)(pAlarmParam->fBankSocDownLimitWarn * 10);  
		iRetVal = 0;
	}
	else if(13 == usRegAddr)    // 组端电压告警上限值    	13	
	{
		usTemp = (quint16)(pAlarmParam->fBankVolUpLimitAlarm * 10);
		iRetVal = 0;
	}
	else if(14 == usRegAddr)    // 组端电压告警下限值	    14
	{
		usTemp = (quint16)(pAlarmParam->fBankVolDownLimitAlarm * 10);
		iRetVal = 0;
	}
	else if(15 == usRegAddr)    // 充电电流告警上限值	    15
	{
		usTemp = (quint16)(pAlarmParam->fChargeCurUpLimitAlarm * 10);
		iRetVal = 0;
	}
	else if(16 == usRegAddr)    // 放电电流告警上限值	    16	
	{
		usTemp = (quint16)(pAlarmParam->fDischargeCurUpLimitAlarm * 10);
		iRetVal = 0;
	}
	else if(17 == usRegAddr)    // 单体电压告警上限值	    17
	{
		usTemp = (quint16)(pAlarmParam->fSglVolUpLimitAlarm * 1000);
		iRetVal = 0;
	}
	else if(18 == usRegAddr)    // 单体电压告警下限值	    18	
	{
		usTemp = (quint16)(pAlarmParam->fSglVolDownLimitAlarm * 1000);
		iRetVal = 0;
	}
	else if(19 == usRegAddr)    // 充电温度告警上限值	    19	
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempUpLimitAlarm * 10);
		iRetVal = 0;
	}
	else if(20 == usRegAddr)    // 充电温度告警下限值	    20
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempDownLimitAlarm * 10);
		iRetVal = 0;
	}
	else if(21 == usRegAddr)    // 放电温度告警上限值	    21	
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempUpLimitAlarm * 10);
		iRetVal = 0;
	}
	else if(22 == usRegAddr)    // 放电温度告警下限值	    22		
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempDownLimitAlarm * 10);
		iRetVal = 0;
	}
	else if(23 == usRegAddr)    // 组SOC告警上限值	        23	
	{
		usTemp = (quint16)(pAlarmParam->fBankSocUpLimitAlarm * 10);  
		iRetVal = 0;
	}
	else if(24 == usRegAddr)    // 组SOC告警下限值	        24	
	{
		usTemp = (quint16)(pAlarmParam->fBankSocDownLimitAlarm * 10);  
		iRetVal = 0;
	}
	else if(25 == usRegAddr)    // 组端电压保护上限值	    25	
	{
		usTemp = (quint16)(pAlarmParam->fBankVolUpLimitProt * 10);
		iRetVal = 0;
	}
	else if(26 == usRegAddr)    // 组端电压保护下限值	    26
	{
		usTemp = (quint16)(pAlarmParam->fBankVolDownLimitProt * 10);
		iRetVal = 0;
	}
	else if(27 == usRegAddr)    // 充电电流保护上限值	    27
	{
		usTemp = (quint16)(pAlarmParam->fChargeCurUpLimitProt * 10);
		iRetVal = 0;
	}
	else if(28 == usRegAddr)    // 放电电流保护上限值	    28	
	{
		usTemp = (quint16)(pAlarmParam->fDischargeCurUpLimitProt * 10);
		iRetVal = 0;
	}
	else if(29 == usRegAddr)    // 单体电压保护上限值	    29	
	{
		usTemp = (quint16)(pAlarmParam->fSglVolUpLimitProt * 1000);
		iRetVal = 0;
	}
	else if(30 == usRegAddr)    // 单体电压保护下限值	    30	
	{
		usTemp = (quint16)(pAlarmParam->fSglVolDownLimitProt * 1000);
		iRetVal = 0;
	}
	else if(31 == usRegAddr)    // 充电温度保护上限值	    31	
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempUpLimitProt * 10);
		iRetVal = 0;
	}
	else if(32 == usRegAddr)    // 充电温度保护下限值	    32	
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempDownLimitProt * 10);
		iRetVal = 0;
	}
	else if(33 == usRegAddr)    // 放电温度保护上限值	    33	
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempUpLimitProt * 10);
		iRetVal = 0;
	}
	else if(34 == usRegAddr)    // 放电温度保护下限值	    34	
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempDownLimitProt * 10);
		iRetVal = 0;
	}
	else if(35 == usRegAddr)    // 组SOC保护上限值	        35	
	{
		usTemp = (quint16)(pAlarmParam->fBankSocUpLimitProt * 10);  
		iRetVal = 0;
	}
	else if(36 == usRegAddr)    // 组SOC保护下限值	        36	
	{
		usTemp = (quint16)(pAlarmParam->fBankSocDownLimitProt * 10);  
		iRetVal = 0;
	}
	else if(37 == usRegAddr)    // 组端电压调整步长(系数)   37
	{		
		usTemp = (quint16)(pBattBank->fBankVolCoe * 10 + 1000);
		iRetVal = 0;
	}
	else if(38 == usRegAddr)    // 充电电流调整步长(系数)   38
	{
		usTemp = (quint16)(pBattBank->fChargeCurCoe * 10 + 1000);  		
		iRetVal = 0;
	}
	else if(39 == usRegAddr)    // 放电电流调整步长(系数)   39
	{		
		usTemp = (quint16)(pBattBank->fDischargeCurCoe * 10 + 1000);		
		iRetVal = 0;
	}
	else if(40 == usRegAddr)    // 环境温度调整步长(系数)   40
	{		
		usTemp = (quint16)(pBattBank->fEnvTempCoe * 10 + 1000);		 
		iRetVal = 0;
	}
	else if(41 == usRegAddr)    // 单体电压调整步长(系数)   41
	{		
		usTemp = (quint16)(pBattBank->fSglVolCoe * 10 + 1000);  		
		iRetVal = 0;
	}
	else if(42 == usRegAddr)    // 单体温度调整步长(系数)   42
	{		
		usTemp = (quint16)(pBattBank->fSglTempCoe * 10 + 1000);
		iRetVal = 0;
	}
	else if(43 == usRegAddr)    // SOC标定基准上限值调整步长(系数)   43
	{		
		usTemp = (quint16)(pBattBank->fBankSocRefUpLmtCoe * 10 + 1000); 		
		iRetVal = 0;
	}
	else if(44 == usRegAddr)    // SOC标定基准下限值调整步长(系数)   44
	{
		usTemp = (quint16)(pBattBank->fBankSocRefDownLmtCoe * 10 + 1000); 
		iRetVal = 0;
	}
	else
	{
		iRetVal = -2;
	}

	if (0 == iRetVal)
	{
		addParam2Buffer(pData, usTemp);
	}

	return iRetVal;	
}


// 保持寄存器 - UINT16 类型
//  0 - 正确处理
// -1 - 错误
// -2 - 地址错误
int CModbusFactory::addHoldRegVal2BufferStack(char* pData, quint16 usRegAddr, CBattStack* pBattStack)
{
	if(!pData || !pBattStack)
	{
		return -1;
	}

	int iRetVal = -999;
	quint16 usTemp = 0;

	if(1 == usRegAddr)    // 并网开关 0x1:启动(Start Connection);     1
	{
		usTemp = pBattStack->usStartConn;
		iRetVal = 0;
	}
	else if (2 == usRegAddr)
	{
		usTemp = pBattStack->usEMSHeartbeat;
		iRetVal = 0;
	}
	else if (3 == usRegAddr)
	{
		usTemp = pBattStack->usYear;
		iRetVal = 0;
	}
	else if (4 == usRegAddr)
	{
		usTemp = pBattStack->usMonth;
		iRetVal = 0;
	}
	else if (5 == usRegAddr)
	{
		usTemp = pBattStack->usDay;
		iRetVal = 0;
	}
	else if (6 == usRegAddr)
	{
		usTemp = pBattStack->usHour;
		iRetVal = 0;
	}
	else if (7 == usRegAddr)
	{
		usTemp = pBattStack->usMin;
		iRetVal = 0;
	}
	else if (8 == usRegAddr)
	{
		usTemp = pBattStack->usSec;
		iRetVal = 0;
	}
	else
	{
		iRetVal = -2;
	}
	
	if (0 == iRetVal)
	{
		addParam2Buffer(pData, usTemp);
	}

	return iRetVal;	
}

// 返回处理的寄存器个数
// 一个寄存器两个字节
quint16 CModbusFactory::addRegVal2BufferUpdate(char* pData, quint16 usRegAddr, CBattStack* pBattStack)
{
	if(!pData || !pBattStack)
	{
		return 1;     // 跳过该寄存器
	}
	
	quint16 usRetVal = 1;
	quint16 usTemp = 0;
	int iTemp = 0;
	quint32 uiTemp = 0;
	quint64 ulTemp = 0;

	if (0x0000 == usRegAddr)               // 主控（BCMU）数量 
	{
		usTemp = pBattStack->usBcNumInStack;     
		addParam2Buffer(pData, usTemp);
		usRetVal = 1;
	}
	else if (0x0001 == usRegAddr)           // 从控（BMU）数量 
	{
		usTemp = pBattStack->usBMUNumInBank;     
		addParam2Buffer(pData, usTemp);
		usRetVal = 1;
	}
	else if (0x03E3 == usRegAddr)   
	{
		uiTemp = (quint32)(pBattStack->ulBaVers >> 32);     
		addParam2Buffer(pData, uiTemp);
		usRetVal = 2;
	}
	else if (0x03E5== usRegAddr)   
	{
		uiTemp = (quint32)pBattStack->ulBaVers;     
		addParam2Buffer(pData, uiTemp);
		usRetVal = 2;
	}
	else if (0x03E7 == usRegAddr)   
	{
		usTemp = pBattStack->usBaUpdateState;     
		addParam2Buffer(pData, usTemp);
		usRetVal = 1;
	}
	else if (usRegAddr >= 0x03E8 && usRegAddr <= 0x03E8 + 200 * 5 - 1)
	{
		iTemp = (usRegAddr - 0x03E8);
		ulTemp = pBattStack->ulBcVers[(int)(iTemp / 5)];

		if (0 == iTemp % 5)
		{
			uiTemp = (quint32)(ulTemp >> 32);     
			addParam2Buffer(pData, uiTemp);
			usRetVal = 2;
		}
		else if (2 == iTemp % 5)
		{
			uiTemp = (quint32)ulTemp; 
			addParam2Buffer(pData, uiTemp);
			usRetVal = 2;
		}
		else if (4 == iTemp % 5)
		{
			usTemp = pBattStack->usBcUpdateState[(int)(iTemp / 5)];     
			addParam2Buffer(pData, usTemp);
			usRetVal = 1;
		}
		else
		{
			usRetVal = 1;
		}
	}

	else if (usRegAddr >= 0x07D0 && usRegAddr <= 0x07D0 + 1600 * 5 - 1)
	{
		iTemp = (usRegAddr - 0x07D0);
		ulTemp = pBattStack->ulBmuVers[(int)(iTemp / 5)];

		if (0 == iTemp % 5)
		{
			uiTemp = (quint32)(ulTemp >> 32);     
			addParam2Buffer(pData, uiTemp);
			usRetVal = 2;
		}
		else if (2 == iTemp % 5)
		{
			uiTemp = (quint32)ulTemp; 
			addParam2Buffer(pData, uiTemp);
			usRetVal = 2;
		}
		else if (4 == iTemp % 5)
		{
			usTemp = pBattStack->usBmuUpdateState[(int)(iTemp / 5)];     
			addParam2Buffer(pData, usTemp);
			usRetVal = 1;
		}
		else
		{
			usRetVal = 1;
		}
	}	
	else
	{
		usRetVal = 1;
	}

	return usRetVal;
}

// 返回处理的寄存器个数
// 一个寄存器两个字节
quint16 CModbusFactory::addRegVal2BufferStack(char* pData, quint16 usRegAddr, CBattStack* pBattStack)
{
	if(!pData || !pBattStack)
	{
		return 1;     // 跳过该寄存器
	}

	quint16 usRetVal = 1;
	quint16 usTemp = 0;
	float fTemp = 0;

	int iRetVal = getRegValStack(usRegAddr, pBattStack, usTemp, fTemp);
	if (1 == iRetVal)
	{
		addParam2Buffer(pData, usTemp);
		usRetVal = 1;
	}
	else if (2 == iRetVal)
	{
		addParam2Buffer(pData, fTemp);
		usRetVal = 2;
	}
	else
	{
		usRetVal = 1;
	}

	return usRetVal;
}

// -1 - Not find
//  1 - quint16 类型
//  2 - float 类型
int CModbusFactory::getRegValStack(quint16 usRegAddr, CBattStack* pBattStack, quint16& usVal, float& fVal)
{
	if (!pBattStack)
	{
		return -1;
	}

	// some variables
	int iRetVal = -1;

	if (0x1001 == usRegAddr)     
	{
		usVal = pBattStack->usConnState;                    // 并网连接状态                      0x1001    1 - 启动(Start Connection);  2 - 成功(Connection Successful);  3 - 结束(Process End)；
		iRetVal = 1;
	}
	else if (0x1002 == usRegAddr)
	{
		usVal = pBattStack->usStackCfgInfo;                 // 电池堆配置信息                    0x1002    0 - 停用   1 - 启用
		iRetVal = 1;
	}
	else if (0x1003 == usRegAddr)
	{
		usVal = pBattStack->usBankReqStepIn;                // Bank 请求切入                     0x1003    0 - 停用   1 - 请求切入
		iRetVal = 1;
	}
	else if (0x1004 == usRegAddr)
	{
		usVal = pBattStack-> usBankReqQuitOut;               // Bank 请求切出                     0x1004    0 - 停用   1 - 请求切出
		iRetVal = 1;
	}
	else if (0x1005 == usRegAddr)
	{
		usVal = pBattStack->usBankInOutState;               // Bank 请求切入切出状态             0x1005    0 - 切出   1 - 切入
		iRetVal = 1;
	}
	else if (0x1006 == usRegAddr)
	{
		usVal = pBattStack->usStackState;                   // 电池堆状态                        0x1006    0 - 正常   1 - 禁充    2 - 禁放    3 - 待机     4 - 停机
		iRetVal = 1;
	}
	else if (0x1007 == usRegAddr)
	{
		usVal = pBattStack->usStackChgDchgState; 	        // 电池堆充放电状态	                 0x1007    0 - 静止   1 - 放电    2 - 充电 
		iRetVal = 1;
	}
	else if (0x1008 == usRegAddr)
	{
		usVal = pBattStack->usStackTotAlarm;                // 电池堆总告警                      0x1008
		iRetVal = 1;
	}
	else if (0x1009 == usRegAddr)
	{
		usVal = pBattStack->usStackWarn;                    // 电池堆预警                        0x1009
		iRetVal = 1;
	}
	else if (0x100A == usRegAddr)
	{
		usVal = pBattStack->usStackAlarm;                   // 电池堆告警                        0x100A
		iRetVal = 1;
	}
	else if (0x100B == usRegAddr)
	{
		usVal = pBattStack->usStackCritical;                // 电池堆严重                        0x100B
		iRetVal = 1;
	}
	else if (0x100C == usRegAddr)
	{	
		usVal = (quint16)(pBattStack->fStackVol * 10);      // 电池堆电压                        0x100C  
		iRetVal = 1;
	}
	else if (0x100D == usRegAddr)
	{
		usVal = (qint16)(pBattStack->fStackCur * -10);      // 电池堆电流                        0x100D    充电电流为负值，放电为正           
		iRetVal = 1;
	}
	else if (0x100E == usRegAddr)
	{
		usVal = (quint16)(pBattStack->fStackSoc * 10);       // 电池堆SOC                         0x100E
		iRetVal = 1;
	}
	else if (0x100F == usRegAddr)
	{
		usVal = (quint16)(pBattStack->fStackSoh * 10); 	    // 电池堆SOH                         0x100F
		iRetVal = 1;
	}
	else if (0x1010 == usRegAddr)
	{		  
		usVal = (quint16)(pBattStack->fStackRes * 100);      // 电池堆绝缘                        0x1010
		iRetVal = 1;
	}
	else if (0x1011 == usRegAddr)
	{
		usVal = (quint16)(pBattStack->fStackChargeEQ); 	     // 电池堆可充电量                    0x1011
		iRetVal = 1;
	}
	else if (0x1012 == usRegAddr)
	{
		usVal = (quint16)(pBattStack->fStackDischargeEQ);    // 电池堆可放电量                    0x1012
		iRetVal = 1;
	}
	else if (0x1013 == usRegAddr)
	{
		usVal = (quint16)(pBattStack->fStackAllowMaxChargeCurrent * 10);      // 电池堆当前允许最大充电电流        0x1013 
		iRetVal = 1;
	}
	else if (0x1014 == usRegAddr)
	{
		usVal = (quint16)(pBattStack->fStackAllowMaxDischargeCurrent * 10);   // 电池堆当前允许最大放电电流        0x1014 
		iRetVal = 1;
	}
	else if (0x1015 == usRegAddr)
	{
		usVal = (quint16)(pBattStack->fBankCurDiff * 10);                     // 组电压差极差值	                 0x1015
		iRetVal = 1;
	}
	else if (0x1016 == usRegAddr)
	{
		usVal = (quint16)(pBattStack->fBankVolDiff * 10);                     // 组电压差极差值	                 0x1016
		iRetVal = 1;
	}
	else if (0x1017 == usRegAddr)
	{
		usVal = pBattStack->usSglMaxVolBankNo;              // 系统最高电压电池所在Rack号        0x1017
		iRetVal = 1;
	}
	else if (0x1018 == usRegAddr)
	{
		usVal = pBattStack->usSglMaxVolPackNo;              // 系统最高电压电池所在箱号(BMU)     0x1018
		iRetVal = 1;
	}
	else if (0x1019 == usRegAddr)
	{
		usVal = pBattStack->usSglMaxVolNoInPack;            // 系统最高电压电池所在位置          0x1019
		iRetVal = 1;
	}
	else if (0x101A == usRegAddr)
	{
		usVal = (quint16)(pBattStack->fSglMaxVolInStack * 1000);                // 最高单体电压   		             0x101A
		iRetVal = 1;
	}
	else if (0x101B == usRegAddr)
	{
		usVal = pBattStack->usSglMinVolBankNo;              // 系统最低电压电池所在Rack号        0x101B
		iRetVal = 1;
	}
	else if (0x101C == usRegAddr)
	{
		usVal = pBattStack->usSglMinVolPackNo;              // 系统最低电压电池所在箱号(BMU)     0x101C
		iRetVal = 1;
	}
	else if (0x101D == usRegAddr)
	{
		usVal = pBattStack->usSglMinVolNoInPack;            // 系统最低电压电池所在位置          0x101D
		iRetVal = 1;
	}
	else if (0x101E == usRegAddr)
	{
		usVal = (quint16)(pBattStack->fSglMinVolInStack * 1000);                // 最低单体电压   		             0x101E
		iRetVal = 1;
	}
	else if (0x101F == usRegAddr)
	{
		usVal = (quint16)(pBattStack->fSglAvgVolInStack * 1000);                // 堆平均单体电压   		         0x101F
		iRetVal = 1;
	}
	else if (0x1020 == usRegAddr)
	{
		usVal = pBattStack->usSglMaxTempBankNo;              // 系统最高温度电池所在Rack号       0x1020
		iRetVal = 1;
	}
	else if (0x1021 == usRegAddr)
	{
		usVal = pBattStack->usSglMaxTempPackNo;              // 系统最高温度电池所在箱号(BMU)    0x1021
		iRetVal = 1;
	}
	else if (0x1022 == usRegAddr)
	{
		usVal = pBattStack->usSglMaxTempNoInPack;            // 系统最高温度电池所在位置         0x1022
		iRetVal = 1;
	}
	else if (0x1023 == usRegAddr)
	{
		usVal = (quint16)(pBattStack->fSglMaxTempInStack * 10); // 最高单体温度   		             0x1023
		iRetVal = 1;
	}
	else if (0x1024 == usRegAddr)
	{
		usVal = pBattStack->usSglMinTempBankNo;              // 系统最低温度电池所在Rack号       0x1024
		iRetVal = 1;
	}
	else if (0x1025 == usRegAddr)
	{
		usVal = pBattStack->usSglMinTempPackNo;              // 系统最低温度电池所在箱号(BMU)    0x1025
		iRetVal = 1;
	}
	else if (0x1026 == usRegAddr)
	{
		usVal = pBattStack->usSglMinTempNoInPack;            // 系统最低温度电池所在位置         0x1026
		iRetVal = 1;
	}
	else if (0x1027 == usRegAddr)
	{
		usVal = (quint16)(pBattStack->fSglMinTempInStack * 10);// 最低单体温度   		             0x1027
		iRetVal = 1;
	}
	else if (0x1028 == usRegAddr)
	{
		usVal = (quint16)(pBattStack->fSglAvgTempInStack * 10); // 堆平均单体温度   		         0x1028   
		iRetVal = 1;
	}
	else if (usRegAddr >= 0x1029 && usRegAddr <= 0x1047)        // 0x1029 - 0x1047          
	{
		usVal = pBattStack->usStackTemp[usRegAddr - 0x1029];
		iRetVal = 1;
	}


	else if (1 == usRegAddr)                                /////////////////////////////////////////////////////////////////////////////////////////// 原来测点
	{
		usVal = pBattStack->usStackState;                   // 电池堆状态                        1           0x1充满 0x2放空 0x3告警 0x4故障 0x0正常          
		iRetVal = 1;
	}
	else if (2 == usRegAddr)
	{
		usVal = pBattStack->usInstallBankNum;               // 安装电池组数                      2          
		iRetVal = 1;
	}
	else if (3 == usRegAddr)
	{
		usVal = pBattStack->usBankNumInStack;               // 电池堆管辖电池组数                3          
		iRetVal = 1;
	}
	else if (4 == usRegAddr)
	{
		usVal = pBattStack->usMaxBankSocNo;                 // 组SOC最大组号                     4          
		iRetVal = 1;
	}
	else if (5 == usRegAddr)
	{
		usVal = pBattStack->usMinBankSocNo;                 // 组SOC最小组号                     5          
		iRetVal = 1;
	}
	else if (6 == usRegAddr)
	{
		usVal = pBattStack->usMaxBankVolNo;                 // 组电压最大组号                    6          
		iRetVal = 1;
	}
	else if (7 == usRegAddr)
	{
		usVal = pBattStack->usMinBankVolNo;                 // 组电压最小组号                    7          
		iRetVal = 1;
	}
	else if (8 == usRegAddr)
	{
		usVal = pBattStack->usSglMaxVolBankNo;              // 最高单体电压电池组号              8          
		iRetVal = 1;
	}
	else if (9 == usRegAddr)
	{
		usVal = pBattStack->usSglMaxVolNoInBank;            // 最高电压电池所在组的组内编号      9          
		iRetVal = 1;
	}
	else if (10 == usRegAddr)
	{
		usVal = pBattStack->usSglMinVolBankNo;              // 最低单体电压电池组号              10          
		iRetVal = 1;
	}
	else if (11 == usRegAddr)
	{
		usVal = pBattStack->usSglMinVolNoInBank;            // 最低电压电池所在组的组内编号      11          
		iRetVal = 1;
	}
	else if (12 == usRegAddr)
	{
		usVal = pBattStack->usSglMaxTempBankNo;             // 最高电池温度电池组号              12          
		iRetVal = 1;
	}
	else if (13 == usRegAddr)
	{
		usVal = pBattStack->usSglMaxTempNoInBank;           // 最高电池温度所在组的组内编号      13          
		iRetVal = 1;
	}
	else if (14 == usRegAddr)
	{
		usVal = pBattStack->usSglMinTempBankNo;             // 最低电池温度电池组号              14          
		iRetVal = 1;
	}
	else if (15 == usRegAddr)
	{
		usVal = pBattStack->usSglMinTempNoInBank;           // 最低电池温度所在组的组内编号      15          
		iRetVal = 1;
	}
	else if (16 == usRegAddr)
	{
		usVal = pBattStack->usDI1;                          // 开关量输入-DI1		             16     1--闭合， 0--断开 
		iRetVal = 1;
	}
	else if (17 == usRegAddr)
	{
		usVal = pBattStack->usDI2;                          // 开关量输入-DI2		             17    
		iRetVal = 1;
	}
	else if (18 == usRegAddr)
	{
		usVal = pBattStack->usDI3;                          // 开关量输入-DI3		             18   
		iRetVal = 1;
	}
	else if (19 == usRegAddr)
	{
		usVal = pBattStack->usDI4;                          // 开关量输入-DI4		             19    
		iRetVal = 1;
	}	
	//else if (usRegAddr >= 20 && usRegAddr <= 50)            // 20 - 50  
	//{
	//	usVal = pBattStack->usStackTemp[usRegAddr - 20];
	//	iRetVal = 1;
	//}

	else if (51 == usRegAddr)
	{
		fVal = pBattStack->fStackVol;                        // 电池堆电压                        51  
		iRetVal = 2;
	}
	else if (53 == usRegAddr)
	{
		fVal = pBattStack->fStackCur; 	                    // 电池堆电流                        53
		iRetVal = 2;
	}
	else if (55 == usRegAddr)
	{
		fVal = pBattStack->fStackSoc;                        // 电池堆SOC                         55
		iRetVal = 2;
	}
	else if (57 == usRegAddr)
	{
		fVal = pBattStack->fStackSoh; 	                    // 电池堆SOH                         57
		iRetVal = 2;
	}
	else if (59 == usRegAddr)
	{
		fVal = pBattStack->fStackChargeEQ; 	                // 电池堆可充电量                    59
		iRetVal = 2;
	}
	else if (61 == usRegAddr)
	{
		fVal = pBattStack->fStackDischargeEQ;                // 电池堆可放电量                    61
		iRetVal = 2;
	}
	else if (63 == usRegAddr)
	{
		fVal = pBattStack->fStackSglChargeEQ;                // 电池堆单次充电电量                63
		iRetVal = 2;
	}
	else if (65 == usRegAddr)
	{
		fVal = pBattStack->fStackSglDischargeEQ;             // 电池堆单次放电电量                65
		iRetVal = 2;
	}
	else if (67 == usRegAddr)
	{
		fVal = pBattStack->fStackChargeEQAdd;                // 电池堆充电量累加值                67
		iRetVal = 2;
	}
	else if (69 == usRegAddr)
	{
		fVal = pBattStack->fStackDischargeEQAdd; 	        // 电池堆放电量累加值                69
		iRetVal = 2;
	}
	else if (71 == usRegAddr)
	{
		fVal = pBattStack->fSglVolDiffInStack;               // 单体电压压差极差值	             71
		iRetVal = 2;
	}
	else if (73 == usRegAddr)
	{
		fVal = pBattStack->fSglMaxVolInStack;                // 最高单体电压   		             73
		iRetVal = 2;
	}
	else if (75 == usRegAddr)
	{
		fVal = pBattStack->fSglMinVolInStack;                // 最低单体电压                      75
		iRetVal = 2;
	}
	else if (77 == usRegAddr)
	{
		fVal = pBattStack->fSglTempDiffInStack;              // 电池温度温差极差值	             77
		iRetVal = 2;
	}
	else if (79 == usRegAddr)
	{
		fVal = pBattStack->fSglMaxTempInStack;               // 最高电池温度                      79
		iRetVal = 2;
	}
	else if (81 == usRegAddr)
	{
		fVal = pBattStack->fSglMinTempInStack;               // 最低电池温度                      81
		iRetVal = 2;
	}
	else if (83 == usRegAddr)
	{
		fVal = pBattStack->fBankSocDiff;                     // 组SOC差极差值	                 83
		iRetVal = 2;
	}
	else if (85 == usRegAddr)
	{
		fVal = pBattStack->fBankSocMax;                      // 组SOC最大                         85
		iRetVal = 2;
	}
	else if (87 == usRegAddr)
	{
		fVal = pBattStack->fBankSocMin;                      // 组SOC最小                         87
		iRetVal = 2;
	}
	else if (89 == usRegAddr)
	{
		fVal = pBattStack->fBankVolDiff;                     // 组电压差极差值	                 89
		iRetVal = 2;
	}
	else if (91 == usRegAddr)
	{
		fVal = pBattStack->fBankVolMax;                      // 组电压最大                        91
		iRetVal = 2;
	}
	else if (93 == usRegAddr)
	{
		fVal = pBattStack->fBankVolMin;                      // 组电压最小                        93
		iRetVal = 2;
	}
	else if (95 == usRegAddr)
	{
		fVal = pBattStack->fStackAllowMaxChargePower;        // 电池堆当前允许最大充电功率        95 
		iRetVal = 2;
	}
	else if (97 == usRegAddr)
	{
		fVal = pBattStack->fStackAllowMaxDischargePower;     // 电池堆当前允许最大放电功率        97 
		iRetVal = 2;
	}
	else if (99 == usRegAddr)
	{
		fVal = pBattStack->fStackAllowMaxChargeCurrent;      // 电池堆当前允许最大充电电流        99 
		iRetVal = 2;
	}
	else if (101 == usRegAddr)
	{
		fVal = pBattStack->fStackAllowMaxDischargeCurrent;   // 电池堆当前允许最大放电电流        101 
		iRetVal = 2;
	}
	else if (usRegAddr >= 103 && usRegAddr <= 200)
	{
		fVal = pBattStack->fStackTemp[(usRegAddr - 103) / 2];
		iRetVal = 2;
	}

	return iRetVal;
}

// RTU
int CModbusFactory::addModbusCRC2Buffer(char *pData, int iLen)
{
	quint16 usCRC = Modbus_CRC16(pData, iLen);

	return addParam2Buffer(pData + iLen, usCRC);
}


//********************************************************************
// FUCTION: Modbus_CRC16 —— MODBUS RTU CRC16校验生成函数
// VERSION: 1	(2010-9-27 14:34:01)
// INPUT:	dat_buf 待校验数值缓存区
// 			dat_len 待校验数值缓存区的长度
// OUTPUT:	CRC16校验值
// EXAMPLE:
// 输入数据 dat_buf指向的数组为： 0x33, 0x78, 0x98, 0x60, 校验长度为4
// 则输出为：高字节0xE4 低字节0x91
//********************************************************************
quint16 CModbusFactory::Modbus_CRC16(char *dat_buf, quint16 usLen)  
{
	/* CRC 高位字节值表 */
	const uchar AUCHCRCHI[256]=
	{
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40
	};
	
	/* CRC 低位字节值表 */
	const uchar AUCHCRCLO[256]=
	{
		0,0xC0,0xC1,0x01,0xC3,0x03,0x02,0xC2,
		0xC6,0x06,0x07,0xC7,0x05,0xC5,0xC4,0x04,
		0xCC,0x0C,0x0D,0xCD,0x0F,0xCF,0xCE,0x0E,
		0x0A,0xCA,0xCB,0x0B,0xC9,0x09,0x08,0xC8,
		0xD8,0x18,0x19,0xD9,0x1B,0xDB,0xDA,0x1A,
		0x1E,0xDE,0xDF,0x1F,0xDD,0x1D,0x1C,0xDC,
		0x14,0xD4,0xD5,0x15,0xD7,0x17,0x16,0xD6,
		0xD2,0x12,0x13,0xD3,0x11,0xD1,0xD0,0x10,
		0xF0,0x30,0x31,0xF1,0x33,0xF3,0xF2,0x32,
		0x36,0xF6,0xF7,0x37,0xF5,0x35,0x34,0xF4,
		0x3C,0xFC,0xFD,0x3D,0xFF,0x3F,0x3E,0xFE,
		0xFA,0x3A,0x3B,0xFB,0x39,0xF9,0xF8,0x38,
		0x28,0xE8,0xE9,0x29,0xEB,0x2B,0x2A,0xEA,
		0xEE,0x2E,0x2F,0xEF,0x2D,0xED,0xEC,0x2C,
		0xE4,0x24,0x25,0xE5,0x27,0xE7,0xE6,0x26,
		0x22,0xE2,0xE3,0x23,0xE1,0x21,0x20,0xE0,
		0xA0,0x60,0x61,0xA1,0x63,0xA3,0xA2,0x62,
		0x66,0xA6,0xA7,0x67,0xA5,0x65,0x64,0xA4,
		0x6C,0xAC,0xAD,0x6D,0xAF,0x6F,0x6E,0xAE,
		0xAA,0x6A,0x6B,0xAB,0x69,0xA9,0xA8,0x68,
		0x78,0xB8,0xB9,0x79,0xBB,0x7B,0x7A,0xBA,
		0xBE,0x7E,0x7F,0xBF,0x7D,0xBD,0xBC,0x7C,
		0xB4,0x74,0x75,0xB5,0x77,0xB7,0xB6,0x76,
		0x72,0xB2,0xB3,0x73,0xB1,0x71,0x70,0xB0,
		0x50,0x90,0x91,0x51,0x93,0x53,0x52,0x92,
		0x96,0x56,0x57,0x97,0x55,0x95,0x94,0x54,
		0x9c,0x5c,0x5d,0x9d,0x5f,0x9f,0x9e,0x5e,
		0x5a,0x9a,0x9b,0x5b,0x99,0x59,0x58,0x98,
		0x88,0x48,0x49,0x89,0x4b,0x8b,0x8a,0x4a,
		0x4e,0x8e,0x8f,0x4f,0x8d,0x4d,0x4c,0x8c,
		0x44,0x84,0x85,0x45,0x87,0x47,0x46,0x86,
		0x82,0x42,0x43,0x83,0x41,0x81,0x80,0x40 
	};
	
	uchar j,CH,CL;
	quint16 i;
	CH = 0XFF;
	CL = 0XFF;
	for(i = 0; i < usLen; i++)
	{
		j = dat_buf[i];
		j = CH ^ j;
		CH = CL ^ AUCHCRCHI[j];
		CL = AUCHCRCLO[j];
	}
	
	return(CH * 0x100 + CL);
}	

// >= 0 OK 返回值
// -1 参数错误
// -2 校验失败
// -3 功能码不正确
// < 0 处理失败
// 06 寄存器地址  值  CRC
// 10 寄存器地址  修改个数  CRC
int CModbusFactory::analyDatagramRtuPCS(char *pData, int iLen)
{
	if(0 == pData || iLen < 4)
	{
		return -1;
	}

	// some varibales
	int iInedx = 0;
	uchar uaModbusAddr = 0;
	uchar uaFuncCode = 0;

	quint16 usTemp16 = 0;

	// 校验报文是否正确
	iInedx = 0;

	uaModbusAddr = *(uchar*)pData;
	++iInedx;

	uaFuncCode = *(uchar*)(pData + iInedx);
	++iInedx;

	// get CRC
	getParamFromBuffer(pData + iLen - 2, usTemp16);

	if(usTemp16 != Modbus_CRC16(pData, iLen - 2))
	{
		return -2;
	}

	if (6 != uaFuncCode && 16 != uaFuncCode)
	{
		return -3;
	}

	return 0;
}

// >= 0 OK 返回值
// -1 参数错误
// -2 功能码不正确
// -3 长度不对
// < 0 处理失败
//int CModbusFactory::analySetHoldReturnDatagram(char* pRecDataBuf, int iLen)
//{
//	if(0 == pRecDataBuf || iLen < 12)
//	{
//		return -1;
//	}
//
//	// some variables
//	int iInedx = 0;
//	quint16 usLen = 0;
//	uchar uaFuncCode = 0;
//
//	// 校验报文是否正确
//	iInedx = 0;
//
//	iInedx += 2;  // 事件标识
//	iInedx += 2;  // 协议标识 
//
//	getParamFromBuffer(pRecDataBuf + iInedx, usLen);
//	iInedx += 2;
//
//	iInedx += 1;  // Modbus Address
//
//	uaFuncCode = (uchar)*(pRecDataBuf + iInedx);
//	iInedx += 1;
//
//	if (6 != uaFuncCode && 16 != uaFuncCode)
//	{
//		return -2;
//	}
//	 
//	if (usLen != 6) 
//	{
//		return -3;
//	}
//
//	return 0;
//}

// >= 0 OK 返回值
// -1 参数错误
// -2 校验失败
// -3 功能码校验失败
// -4 事务号不正确
// -5 未知步骤

// < 0 处理失败
int CModbusFactory::analyDatagram(int iIndexStep, char* pRecDataBuf, int iLen, CBattBank* pCurBatt)
{
	if(0 == pRecDataBuf || iLen < 9 || 0 == pCurBatt)
	{
		return -1;
	}

	// some varibales
	int iRetVal = 0;
	int iInedx = 0;
	quint16 usEvent = 0;
	quint16 usLen = 0;
	uchar uaModbusAddr = 0;
	uchar uaFuncCode = 0;
	uchar uaByteNum = 0;

	uchar uaTemp8 = 0;
	quint16 usTemp16 = 0;
	float fTemp = 0;

	// 校验报文是否正确
	iInedx = 0;

	getParamFromBuffer(pRecDataBuf, usEvent);
	iInedx += 2;

	iInedx += 2;  // 协议标识 

	getParamFromBuffer(pRecDataBuf + iInedx, usLen);
	iInedx += 2;

	uaModbusAddr = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	uaFuncCode = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	// 字节数
	uaByteNum = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	if (pCurBatt->uaModbusAddr != uaModbusAddr || iLen != usLen + 6 || usLen != uaByteNum + 3) // 校验失败
	{
		return -2;
	}

	switch (iIndexStep)
	{
	case 0: // formDatagram(1/*读取告警状态*/, uaAddr, 2, 1, 34, pSendDataBuf);	          // 离散输入寄存器 1 ~ 50
		if(2 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (1 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			// 7 字节
			uaTemp8 = (uchar)*(pRecDataBuf + iInedx); // 1 ~ 8
			iInedx += 1;

			pCurBatt->aSglVolUpLimitAlarm = (char)(uaTemp8 & 0x01);          // 单体电压过高告警       1
			uaTemp8 = uaTemp8 >> 1;		
			pCurBatt->aSglVolDownLimitAlarm = (char)(uaTemp8 & 0x01);	     // 单体电压过低告警       2
			uaTemp8 = uaTemp8 >> 1;	
			pCurBatt->aSglTempUpLimitAlarm = (char)(uaTemp8 & 0x01);		 // 单体温度过高告警	   3
			uaTemp8 = uaTemp8 >> 1;	
			pCurBatt->aSglTempDownLimitAlarm = (char)(uaTemp8 & 0x01);		 // 单体温度过低告警	   4
			uaTemp8 = uaTemp8 >> 1;	
			pCurBatt->aSglVolUpLimitProt = (char)(uaTemp8 & 0x01);			 // 单体电压过高保护	   5
			uaTemp8 = uaTemp8 >> 1;	
			pCurBatt->aSglVolDownLimitProt = (char)(uaTemp8 & 0x01);		 // 单体电压过低保护	   6
			uaTemp8 = uaTemp8 >> 1;	
			pCurBatt->aSglTempUpLimitProt = (char)(uaTemp8 & 0x01);	         // 单体温度过高保护	   7
			uaTemp8 = uaTemp8 >> 1;	
			pCurBatt->aSglTempDownLimitProt = (char)(uaTemp8 & 0x01);		 // 单体温度过低保护	   8	
			uaTemp8 = uaTemp8 >> 1;	

			uaTemp8 = (uchar)*(pRecDataBuf + iInedx); // 9 ~ 16
			iInedx += 1;

			pCurBatt->aBankVolUpLimitAlarm = (char)(uaTemp8 & 0x01);	     // 组电压过高告警         9
			uaTemp8 = uaTemp8 >> 1;	
			pCurBatt->aBankVolDownLimitAlarm = (char)(uaTemp8 & 0x01);	     // 组电压过低告警         10
			uaTemp8 = uaTemp8 >> 1;	
	//		pCurBatt->aBankCurUpLimitAlarm = (char)(uaTemp8 & 0x01);		 // 组电流过高告警         11
			uaTemp8 = uaTemp8 >> 1;	
			pCurBatt->aEnvTempUpLimitAlarm = (char)(uaTemp8 & 0x01);		 // 环境温度过高告警	   12
			uaTemp8 = uaTemp8 >> 1;	
			pCurBatt->aEnvTempDownLimitAlarm = (char)(uaTemp8 & 0x01);		 // 环境温度过低告警	   13
			uaTemp8 = uaTemp8 >> 1;	
			pCurBatt->aBankSocDownLimitAlarm = (char)(uaTemp8 & 0x01);		 // SOC超下限告警		   14
			uaTemp8 = uaTemp8 >> 1;	
			pCurBatt->aBankVolUpLimitProt = (char)(uaTemp8 & 0x01);			 // 组电压过高保护	       15
			uaTemp8 = uaTemp8 >> 1;	
			pCurBatt->aBankVolDownLimitProt = (char)(uaTemp8 & 0x01);		 // 组电压过低保护	       16	
			uaTemp8 = uaTemp8 >> 1;	

			uaTemp8 = (uchar)*(pRecDataBuf + iInedx); // 17 ~ 24
			iInedx += 1;

		//	pCurBatt->aBankCurUpLimitProt = (char)(uaTemp8 & 0x01);			 // 组电流过高保护		   17
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aEnvTempUpLimitProt = (char)(uaTemp8 & 0x01);			 // 环境温度过高保护	   18
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aEnvTempDownLimitProt = (char)(uaTemp8 & 0x01);		 // 环境温度过低保护	   19	
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aBankSocDownLimitProt = (char)(uaTemp8 & 0x01);		 // SOC超下限保护		   20
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aBMUConnFaultAlarm = (char)(uaTemp8 & 0x01);			 // BMU设备连接故障告警	   21
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aBCMUConnFaultAlarm = (char)(uaTemp8 & 0x01);			 // BCMU设备连接故障告警   22
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aSglVolUpLimitWarn = (char)(uaTemp8 & 0x01);		     // 单体电压过高预警	   23
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aSglVolDownLimitWarn = (char)(uaTemp8 & 0x01);	 // 单体电压过低预警	   24
			//uaTemp8 = uaTemp8 >> 1;	

			//uaTemp8 = (uchar)*(pRecDataBuf + iInedx); // 25 ~ 32
			//iInedx += 1;

			//pCurBatt->aSglTempUpLimitWarn = (char)(uaTemp8 & 0x01);          // 单体温度过高预警	   25	
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aSglTempDownLimitWarn = (char)(uaTemp8 & 0x01);        // 单体温度过低预警     26
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aBankSocUpLimitAlarm = (char)(uaTemp8 & 0x01);         // SOC超上限告警		   27
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aBankSocUpLimitProt = (char)(uaTemp8 & 0x01);          // SOC超上限保护		   28
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aPosResDwonLimitProt = (char)(uaTemp8 & 0x01);         // 正极绝缘内阻下限保护  29
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aNegResDwonLimitProt = (char)(uaTemp8 & 0x01);         // 负极绝缘内阻下限保护  30
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aPackVolDiffUpLimitAlarm = (char)(uaTemp8 & 0x01);     // 箱压差上限告警         31
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aPackVolDiffUpLimitProt = (char)(uaTemp8 & 0x01);      // 箱压差上限保护         32
			//uaTemp8 = uaTemp8 >> 1;	

			//uaTemp8 = (uchar)*(pRecDataBuf + iInedx); // 33 ~ 40
			//iInedx += 1;

			//pCurBatt->aPackTempDiffUpLimitAlarm = (char)(uaTemp8 & 0x01);      // 箱温差上限告警         33	
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aPackTempDiffUpLimitProt = (char)(uaTemp8 & 0x01);       // 箱温差上限保护         34
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aBankVolUpLimitWarn = (char)(uaTemp8 & 0x01);            // 组电压过高预警         35
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aBankVolDownLimitWarn = (char)(uaTemp8 & 0x01);          // 组电压过低预警         36
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aBankCurUpLimitWarn = (char)(uaTemp8 & 0x01);            // 组电流过高预警         37
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aEnvTempUpLimitWarn = (char)(uaTemp8 & 0x01);            // 环境温度过高预警	   38
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aEnvTempDownLimitWarn = (char)(uaTemp8 & 0x01);          // 环境温度过低预警	   39
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aBankSocUpLimitWarn = (char)(uaTemp8 & 0x01);            // SOC超上限预警		   40
			//uaTemp8 = uaTemp8 >> 1;	

			//uaTemp8 = (uchar)*(pRecDataBuf + iInedx); // 41 ~ 48
			//iInedx += 1;

			//pCurBatt->aBankSocDownLimitWarn = (char)(uaTemp8 & 0x01);          // SOC超下限预警		   41
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aPackVolDiffUpLimitWarn = (char)(uaTemp8 & 0x01);        // 箱压差上限预警       42
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aPackTempDiffUpLimitWarn = (char)(uaTemp8 & 0x01);       // 箱温差上限预警       43
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aBkwdSglVolReptProt = (char)(uaTemp8 & 0x01);            // 落后电池电压多次保护   44
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aSglVolWireFault = (char)(uaTemp8 & 0x01);               // 单体电压采集线故障     45
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aBankVolWireFault = (char)(uaTemp8 & 0x01);              // 总压采集线故障         46
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aCurWireFault = (char)(uaTemp8 & 0x01);                  // 电流采集线故障         47
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aTempWireBreak = (char)(uaTemp8 & 0x01);                 // 温度采集断线           48
			//uaTemp8 = uaTemp8 >> 1;	

			//uaTemp8 = (uchar)*(pRecDataBuf + iInedx); // 49 
			//iInedx += 1;

			//pCurBatt->aTempShortCircuit = (char)(uaTemp8 & 0x01);              // 温度采集短路           49
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aBMSFault = (char)(uaTemp8 & 0x01);                      // BMS设备故障            50
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aBankCurAbnormity = (char)(uaTemp8 & 0x01);              // 组电流异常             51
			//uaTemp8 = uaTemp8 >> 1;	
			//pCurBatt->aAlarmAvailable = (char)(uaTemp8 & 0x01);                // 告警信息待获取         52
			//uaTemp8 = uaTemp8 >> 1;	

			iRetVal = 0;
		}			          
		break;

	case 1: // formDatagram(8/*读取电池1~50 电压*/, uaAddr, 4, 1, 100, pSendDataBuf);	      // 输入寄存器 1 ~ 99
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (8 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 0; i < 50; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglVol[i] = fTemp; // 单体电压            
			}

			iRetVal = 0;
		}	
		break;
	case 2: // formDatagram(9/*读取电池51~100电压*/, uaAddr, 4, 101, 100, pSendDataBuf);	      // 输入寄存器 101 ~ 199
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (9 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 50; i < 100; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglVol[i] = fTemp; // 单体电压               
			}

			iRetVal = 0;
		}	
		break;
	case 3: // formDatagram(10/*读取电池101~150电压*/, uaAddr, 4, 201, 100, pSendDataBuf);	  // 输入寄存器 201 ~ 299
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (10 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 100; i < 150; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglVol[i] = fTemp; // 单体电压               
			}
			iRetVal = 0;
		}	
		break;
	case 4: // formDatagram(11/*读取电池151~200电压*/, uaAddr, 4, 301, 100, pSendDataBuf);	  // 输入寄存器 301 ~ 399
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (11 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 150; i < 200; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglVol[i] = fTemp; // 单体电压              
			}
			iRetVal = 0;
		}	
		break;
	case 5: // formDatagram(12/*读取电池201~250电压*/, uaAddr, 4, 401, 100, pSendDataBuf);	  // 输入寄存器 401 ~ 499
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (12 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 200; i < 250; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglVol[i] = fTemp; // 单体电压               
			}
			iRetVal = 0;
		}	
		break;
	case  6: // formDatagram(13/*读取电池251~300电压*/, uaAddr, 4, 501, 100, pSendDataBuf);	  // 输入寄存器 501 ~ 599
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (13 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 250; i < 300; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglVol[i] = fTemp; // 单体电压              
			}
			iRetVal = 0;
		}	
		break;
	case 7: // formDatagram(14/*读取电池301~350电压*/, uaAddr, 4, 601, 100, pSendDataBuf);	  // 输入寄存器 601 ~ 699
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (14 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 300; i < 350; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglVol[i] = fTemp; // 单体电压             
			}
			iRetVal = 0;
		}	
		break;
	case 8: // formDatagram(15/*读取电池350~400电压*/, uaAddr, 4, 701, 100, pSendDataBuf);	  // 输入寄存器 701 ~ 799 
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (15 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 350; i < 400; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglVol[i] = fTemp; // 单体电压                
			}
			iRetVal = 0;
		}	
		break;

	case 9: // formDatagram(16/*读取电池1~50 温度*/, uaAddr, 4, 801, 100, pSendDataBuf);	  // 输入寄存器 801 ~ 899
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (16 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 0; i < 50; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglTemp[i] = fTemp; // 单体温度              
			}

			iRetVal = 0;
		}	
		break;
	case 10: // formDatagram(17/*读取电池51~100温度*/, uaAddr, 4, 901, 100, pSendDataBuf);	  // 输入寄存器 901 ~ 999
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (17 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 50; i < 100; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglTemp[i] = fTemp; // 单体温度          
			}
			iRetVal = 0;
		}	
		break;
	case 11: // formDatagram(18/*读取电池101~150温度*/, uaAddr, 4, 1001, 100, pSendDataBuf);	  // 输入寄存器 1001 ~ 1099
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (18 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 100; i < 150; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglTemp[i] = fTemp; // 单体温度              
			}
			iRetVal = 0;
		}	
		break;
	case 12: // formDatagram(19/*读取电池151~200温度*/, uaAddr, 4, 1101, 100, pSendDataBuf);	  // 输入寄存器 1101 ~ 1199
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (19 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 150; i < 200; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglTemp[i] = fTemp; // 单体温度             
			}
			iRetVal = 0;
		}	
		break;
	case 13: // formDatagram(20/*读取电池201~250温度*/, uaAddr, 4, 1201, 100, pSendDataBuf);	  // 输入寄存器 1201 ~ 1299
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (20 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 200; i < 250; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglTemp[i] = fTemp; // 单体温度              
			}
			iRetVal = 0;
		}	
		break;
	case 14: // formDatagram(21/*读取电池251~300温度*/, uaAddr, 4, 1301, 100, pSendDataBuf);	  // 输入寄存器 1301 ~ 1399
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (21 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 250; i < 300; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglTemp[i] = fTemp; // 单体温度              
			}
			iRetVal = 0;
		}	
		break;
	case 15: // formDatagram(22/*读取电池301~350温度*/, uaAddr, 4, 1401, 100, pSendDataBuf);	  // 输入寄存器 1401 ~ 1499
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (22 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 300; i < 350; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglTemp[i] = fTemp; // 单体温度             
			}
			iRetVal = 0;
		}	
		break;
	case 16: // formDatagram(23/*读取电池350~400温度*/, uaAddr, 4, 1501, 100, pSendDataBuf);	  // 输入寄存器 1501 ~ 1599
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (23 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 350; i < 400; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglTemp[i] = fTemp; // 单体温度              
			}
			iRetVal = 0;
		}	
		break;

	case 17: // formDatagram(24/*读取电池1~50 Soc*/, uaAddr, 4, 1601, 100, pSendDataBuf);	      // 输入寄存器 1601 ~ 1699
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (24 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 0; i < 50; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoc[i] = fTemp;  // 单体Soc           
			}
			iRetVal = 0;
		}	
		break;
	case 18: // formDatagram(25/*读取电池51~100Soc*/, uaAddr, 4, 1701, 100, pSendDataBuf);	  // 输入寄存器 1701 ~ 1799
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (25 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 50; i < 100; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoc[i] = fTemp;  // 单体Soc              
			}
			iRetVal = 0;
		}	
		break;
	case 19: // formDatagram(26/*读取电池101~150Soc*/, uaAddr, 4, 1801, 100, pSendDataBuf);	  // 输入寄存器 1801 ~ 1899
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (26 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 100; i < 150; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoc[i] = fTemp;  // 单体Soc               
			}
			iRetVal = 0;
		}	
		break;
	case 20: // formDatagram(27/*读取电池151~200Soc*/, uaAddr, 4, 1901, 100, pSendDataBuf);	  // 输入寄存器 1901 ~ 1999
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (27 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 150; i < 200; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoc[i] = fTemp;  // 单体Soc             
			}
			iRetVal = 0;
		}	
		break;
	case 21: // formDatagram(28/*读取电池201~250Soc*/, uaAddr, 4, 2001, 100, pSendDataBuf);	  // 输入寄存器 2001 ~ 2099
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (28 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 200; i < 250; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoc[i] = fTemp;  // 单体Soc              
			}
			iRetVal = 0;
		}	
		break;
	case 22: // formDatagram(29/*读取电池251~300Soc*/, uaAddr, 4, 2101, 100, pSendDataBuf);	  // 输入寄存器 2101 ~ 2199
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (29 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 250; i < 300; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoc[i] = fTemp;  // 单体Soc               
			}
			iRetVal = 0;
		}	
		break;
	case 23: // formDatagram(30/*读取电池301~350Soc*/, uaAddr, 4, 2201, 100, pSendDataBuf);	  // 输入寄存器 2201 ~ 2299
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (30 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 300; i < 350; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoc[i] = fTemp;  // 单体Soc              
			}
			iRetVal = 0;
		}	
		break;
	case 24: // formDatagram(31/*读取电池350~400Soc*/, uaAddr, 4, 2301, 100, pSendDataBuf);	  // 输入寄存器 2301 ~ 2399
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (31 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 350; i < 400; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoc[i] = fTemp;  // 单体Soc              
			}
			iRetVal = 0;
		}	
		break;

	case 25: // formDatagram(32/*读取电池1~50 内阻*/, uaAddr, 4, 2401, 100, pSendDataBuf);	  // 输入寄存器 2401 ~ 2499
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (32 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 0; i < 50; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglRes[i] = fTemp;   // 单体内阻             
			}

			iRetVal = 0;
		}	
		break;
	case 26: // formDatagram(33/*读取电池51~100内阻*/, uaAddr, 4, 2501, 100, pSendDataBuf);	  // 输入寄存器 2501 ~ 2599
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (33 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 50; i < 100; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglRes[i] = fTemp;   // 单体内阻             
			}
			iRetVal = 0;
		}	
		break;
	case 27: // formDatagram(34/*读取电池101~150内阻*/, uaAddr, 4, 2601, 100, pSendDataBuf);	  // 输入寄存器 2601 ~ 2699
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (34 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 100; i < 150; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglRes[i] = fTemp;   // 单体内阻               
			}
			iRetVal = 0;
		}	
		break;
	case 28: // formDatagram(35/*读取电池151~200内阻*/, uaAddr, 4, 2701, 100, pSendDataBuf);	  // 输入寄存器 2701 ~ 2799
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (35 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 150; i < 200; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglRes[i] = fTemp;   // 单体内阻             
			}
			iRetVal = 0;
		}	
		break;
	case 29: // formDatagram(36/*读取电池201~250内阻*/, uaAddr, 4, 2801, 100, pSendDataBuf);	  // 输入寄存器 2801 ~ 2899
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (36 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 200; i < 250; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglRes[i] = fTemp;   // 单体内阻              
			}
			iRetVal = 0;
		}	
		break;
	case 30: // formDatagram(37/*读取电池251~300内阻*/, uaAddr, 4, 2901, 100, pSendDataBuf);	  // 输入寄存器 2901 ~ 2999
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (37 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 250; i < 300; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglRes[i] = fTemp;   // 单体内阻            
			}
			iRetVal = 0;
		}	
		break;
	case 31: // formDatagram(38/*读取电池301~350内阻*/, uaAddr, 4, 3001, 100, pSendDataBuf);	  // 输入寄存器 3001 ~ 3099
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (38 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 300; i < 350; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglRes[i] = fTemp;   // 单体内阻             
			}
			iRetVal = 0;
		}	
		break;
	case 32: // formDatagram(39/*读取电池350~400内阻*/, uaAddr, 4, 3101, 100, pSendDataBuf);	  // 输入寄存器 3101 ~ 3199
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (39 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 350; i < 400; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglRes[i] = fTemp;   // 单体内阻             
			}
			iRetVal = 0;
		}	
		break;

	case 33: // formDatagram(40/*读取电池1~50 Soh*/, uaAddr, 4, 3201, 100, pSendDataBuf);	      // 输入寄存器 3201 ~ 3299
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (40 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 0; i < 50; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoh[i] = fTemp;  // 单体Soh               
			}

			iRetVal = 0;
		}	
		break;
	case 34: // formDatagram(41/*读取电池51~100Soh*/, uaAddr, 4, 3301, 100, pSendDataBuf);	  // 输入寄存器 3301 ~ 3399
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (41 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 50; i < 100; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoh[i] = fTemp;  // 单体Soh              
			}
			iRetVal = 0;
		}	
		break;
	case 35: // formDatagram(42/*读取电池101~150Soh*/, uaAddr, 4, 3401, 100, pSendDataBuf);	  // 输入寄存器 3401 ~ 3499
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (42 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 100; i < 150; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoh[i] = fTemp;  // 单体Soh               
			}
			iRetVal = 0;
		}	
		break;
	case 36: // formDatagram(43/*读取电池151~200Soh*/, uaAddr, 4, 3501, 100, pSendDataBuf);	  // 输入寄存器 3501 ~ 3599
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (43 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 150; i < 200; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoh[i] = fTemp;  // 单体Soh               
			}
			iRetVal = 0;
		}	
		break;
	case 37: // formDatagram(44/*读取电池201~250Soh*/, uaAddr, 4, 3601, 100, pSendDataBuf);	  // 输入寄存器 3601 ~ 3699
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (44 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 200; i < 250; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoh[i] = fTemp;  // 单体Soh               
			}
			iRetVal = 0;
		}	
		break;
	case 38: // formDatagram(45/*读取电池251~300Soh*/, uaAddr, 4, 3701, 100, pSendDataBuf);	  // 输入寄存器 3701 ~ 3799
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (45 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 250; i < 300; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoh[i] = fTemp;  // 单体Soh                
			}
			iRetVal = 0;
		}	
		break;
	case 39: // formDatagram(46/*读取电池301~350Soh*/, uaAddr, 4, 3801, 100, pSendDataBuf);	  // 输入寄存器 3801 ~ 3899
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (46 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 300; i < 350; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoh[i] = fTemp;  // 单体Soh              
			}
			iRetVal = 0;
		}	
		break;
	case 40: // formDatagram(47/*读取电池350~400Soh*/, uaAddr, 4, 3901, 100, pSendDataBuf);	  // 输入寄存器 3901 ~ 3999
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (47 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 350; i < 400; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

				pCurBatt->fSglSoh[i] = fTemp;  // 单体Soh                
			}
			iRetVal = 0;
		}	
		break;


	case 41: // formDatagram(48/*读取其他浮点数*/, uaAddr, 4, 4001, 56, pSendDataBuf);	      // 输入寄存器 4001 ~ 4055
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (48 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBCMUBankVol = fTemp; 	         // BCMU组端电压		   4001

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBCMUBankCur = fTemp; 	         // BCMU组电流		       4003

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBCMUBankTemp = fTemp; 	         // BCMU环境温度		   4005

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBCMUPosRes = fTemp; 	             // BCMU 正极绝缘电阻	   4007

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBCMUNegRes = fTemp;               // BCMU 负极绝缘电阻	   4009

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglAvgVol = fTemp;                // 单体电压平均值         4011

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglMaxVol = fTemp;                // 单电电压最大值         4013	

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglMinVol = fTemp; 	             // 单电电压最小值	       4015	

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglAvgTemp = fTemp; 	             // 单体温度平均值         4017

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglMaxTemp = fTemp;               // 单电温度最大值	       4019	

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglMinTemp = fTemp;               // 单电温度最小值	       4021	

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglAvgRes = fTemp;                // 单体平均内阻	       4023

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglMaxRes = fTemp;                // 单体内阻最大值	       4025	

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglMinRes = fTemp;                // 单体内阻最小值		   4027

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglAvgSoc = fTemp; 	             // 单体SOC平均值          4029

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglMaxSoc = fTemp;                // 单体SOC最大值		   4031

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglMinSoc = fTemp;                // 单体SOC最小值	       4033	

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglAvgSoh = fTemp;                // 单体SOH平均值          4035

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglMaxSoh = fTemp;                // 单体SOH最大值	       4037	

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fSglMinSoh = fTemp;                // 单体SOH最小值	       4039	

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBankSoc = fTemp;                  // 组SOC		           4041

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBankSoh = fTemp;                  // 组SOH	               4043

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBankChargeEQ = fTemp; 	         // 电池组可充电量         4045 

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBankDischargeEQ = fTemp; 	     // 电池组可放电量	       4047	

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBankChargeEQAdd = fTemp; 	     // 电池组累计充电电量	   4049

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBankDischargeEQAdd = fTemp;       // 电池组累计放电电量	   4051

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBankSglChargeEQAdd = fTemp;     	 // 电池组单次累计充电电量 4053

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBankSglDischargeEQAdd = fTemp; 	 // 电池组单次累计放电电量 4055

			iRetVal = 0;
		}	
		break;

	case 42: // formDatagram(49/*读取其他短整形数*/, uaAddr, 4, 5001, 25, pSendDataBuf);	  // 输入寄存器 5001 ~ 5025
		if(4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (49 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
			pCurBatt->usSglMaxVolNo = usTemp16;           // 单电最大电压对应ID号   5001

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
			pCurBatt->usSglMinVolNo = usTemp16;           // 单电最小电压对应ID号   5002

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
			pCurBatt->usSglMaxTempNo = usTemp16;          // 单电最大温度对应ID号   5003

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
			pCurBatt->usSglMinTempNo = usTemp16;          // 单电最小温度对应ID号   5004

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
			pCurBatt->usSglMaxResNo = usTemp16;           // 单电最大内阻对应ID号   5005

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
			pCurBatt->usSglMinResNo = usTemp16;           // 单电最小内阻对应ID号   5006

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
			pCurBatt->usSglMaxSocNo = usTemp16;           // 单电最大SOC对应ID号    5007

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
			pCurBatt->usSglMinSocNo = usTemp16;           // 单电最小SOC对应ID号    5008

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
			pCurBatt->usSglMaxSohNo = usTemp16;           // 单电最大SOH对应ID号    5009

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
			pCurBatt->usSglMinSohNo = usTemp16;           // 单电最小SOH对应ID号    5010	

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
			pCurBatt->usBankState = usTemp16;             // 蓄电池组充放电状态     5011    1 - 开路 2 - 待机 3 - 充电  4 - 放电   // 0—浮充；1—充电；2—放电；3—开路；4—过充；5—欠充；6—开路

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
			//pCurBatt->usBankStatePCS = usTemp16; 	     // 电池组状态（告知PCS）	5012    0x1充满，0x2放空，0x3待机，0x4跳机，0x0正常

			//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			//iInedx += 2;
			//pCurBatt->usBCMUInput1 = usTemp16;            // BCMU开关状态寄存器Input 1（直流接触器状态）		5013    1--闭合， 0--断开

			//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			//iInedx += 2;
			//pCurBatt->usBCMUInput2 = usTemp16; 	         // BCMU Input 2（熔断器1状态）                    	5014

			//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			//iInedx += 2;
			//pCurBatt->usBCMUInput3 = usTemp16; 	         // BCMU Input 3（熔断器2状态）	                    5015

			//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			//iInedx += 2;
			//pCurBatt->usBCMUInput4 = usTemp16; 	         // BCMU Input 4（手动空开状态）		            5016

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBankMaxChargePower = fTemp; 	     // 电池组最大充电功率                              5017 

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBankMaxDischargePower = fTemp; 	 // 电池组最大放电功率                              5019

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBankMaxChargeCurrent = fTemp; 	// 电池组最大充电电流                              5021

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
			//pCurBatt->fBankMaxDischargeCurrent = fTemp; // 电池组最大放电电流                              5023 	

			//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			//iInedx += 2;
			//pCurBatt->usResTestState = usTemp16; 	     // 绝缘检测状态                                   5025

			iRetVal = 0;
		}	
		break;
	default:
		iRetVal = -5;
		break;
	}

	return iRetVal;
}

// 解析电池堆读保持寄存器 0x03 
// >= 0 OK 返回值
// -1 参数错误
// -2 校验失败

// < 0 处理失败
int CModbusFactory::analyStackHoldDatagram(char* pRecDataBuf, int iLen, CBattStack* pStack)
{
	if(0 == pRecDataBuf || iLen < 11 || 0 == pStack)
	{
		return -1;
	}

	// some varibales
	int iInedx = 0;
	quint16 usEvent = 0;
	quint16 usLen = 0;
	uchar uaModbusAddr = 0;
	uchar uaFuncCode = 0;
	uchar uaByteNum = 0;

	quint16 usTemp16 = 0;

	// 校验报文是否正确
	iInedx = 0;

	getParamFromBuffer(pRecDataBuf, usEvent);
	iInedx += 2;

	iInedx += 2;  // 协议标识 

	getParamFromBuffer(pRecDataBuf + iInedx, usLen);
	iInedx += 2;

	uaModbusAddr = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	uaFuncCode = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	// 字节数
	uaByteNum = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	if (202 != usEvent || 1 != uaModbusAddr || iLen != usLen + 6 || usLen != uaByteNum + 3 || 3 != uaFuncCode) // 校验失败
	{
		return -2;
	}

	// data  
	getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
	pStack->usDelayBeforeCutCntor = usTemp16;

	return  0;
}

// >= 0 OK 返回值
// -1 参数错误
// -2 长度不正确
// -3 功能码不正确

// < 0 处理失败
int CModbusFactory::analyComInputRegDatagram(char* pRecDataBuf, int iLen, quint16* pComInputRegData)
{
	if(0 == pRecDataBuf || iLen < 9 || 0 == pComInputRegData)
	{
		return -1;
	}

	// some varibales
	int iInedx = 0;
	quint16 usEvent = 0;
	quint16 usLen = 0;
	uchar uaModbusAddr = 0;
	uchar uaFuncCode = 0;
	uchar uaByteNum = 0;
	quint16 usTemp16 = 0;

	// 校验报文是否正确
	iInedx = 0;

	getParamFromBuffer(pRecDataBuf, usEvent);
	iInedx += 2;

	iInedx += 2;  // 协议标识 

	getParamFromBuffer(pRecDataBuf + iInedx, usLen);
	iInedx += 2;

	uaModbusAddr = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	uaFuncCode = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	// 字节数
	uaByteNum = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	if (100 != uaModbusAddr || 4 != uaFuncCode || iLen != usLen + 6 || usLen != uaByteNum + 3 || uaByteNum != 200) // 校验失败
	{
		return -2;
	}

	if (200 != usEvent)
	{
		return -4;
	}

	for (int i = 0; i < 100; ++i)
	{
		getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		iInedx += 2;

		*(pComInputRegData + i) = usTemp16;
	}

	return 0;
}

// >= 0 OK 返回值
// -1 参数错误
// -2 校验失败
// -3 功能码校验失败
// -4 事务号不正确
// < 0 处理失败
int CModbusFactory::analyStackDatagram(char* pRecDataBuf, int iLen, CBattStack* pStack)
{
	if(0 == pRecDataBuf || iLen < 9 || 0 == pStack)
	{
		return -1;
	}

	// some varibales
	int iRetVal = 0;
	int iInedx = 0;
	quint16 usEvent = 0;
	quint16 usLen = 0;
	uchar uaModbusAddr = 0;
	uchar uaFuncCode = 0;
	uchar uaByteNum = 0;

	quint16 usTemp16 = 0;
	float fTemp = 0;

	// 校验报文是否正确
	iInedx = 0;

	getParamFromBuffer(pRecDataBuf, usEvent);
	iInedx += 2;

	iInedx += 2;  // 协议标识 

	getParamFromBuffer(pRecDataBuf + iInedx, usLen);
	iInedx += 2;

	uaModbusAddr = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	uaFuncCode = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	// 字节数
	uaByteNum = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	if (1 != uaModbusAddr || iLen != usLen + 6 || usLen != uaByteNum + 3) // 校验失败
	{
		iRetVal = -2;
	}
	else if(4 != uaFuncCode)
	{
		iRetVal = -3;
	}
	else if (201 != usEvent)
	{
		iRetVal = -4;
	}
	else
	{
		getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		iInedx += 2;
		pStack->usStackState = usTemp16;           // 电池堆状态            1          0x1充满 0x2放空 0x3告警 0x4故障 0x0正常

		getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		iInedx += 4;
		pStack->fStackSoc = fTemp;                // 电池堆SOC             2

		getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		iInedx += 4;
		pStack->fStackSoh = fTemp; 	              // 电池堆SOH             4

		getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		iInedx += 4;
		pStack->fStackChargeEQ = fTemp; 	      // 电池堆可充电量        6

		getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		iInedx += 4;
		pStack->fStackDischargeEQ = fTemp;        // 电池堆可放电量        8

		getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		iInedx += 4;
		pStack->fStackChargeEQAdd = fTemp;        // 电池堆充电量累加值    10

		getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		iInedx += 4;
		pStack->fStackDischargeEQAdd = fTemp;     // 电池堆放电量累加值    12

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fStackTotalVol = fTemp;           // 电池堆总电压         14  

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fStackTotalCur = fTemp; 	      // 电池堆总电流         16

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranParalState1 = usTemp16;     // 第1支路并联状态      18  1--闭合，2--断开

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranParalState2 = usTemp16;     // 第2支路并联状态      19

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranParalState3 = usTemp16; 	  // 第3支路并联状态      20

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranParalState4 = usTemp16; 	  // 第4支路并联状态      21

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranSoc1 = fTemp; 	             // 第1支路电池SOC       22

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranSoc2 = fTemp; 	             // 第2支路电池SOC       24

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranSoc3 = fTemp; 	             // 第3支路电池SOC       26

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranSoc4 = fTemp; 	             // 第4支路电池SOC       28

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranCur1 = fTemp; 	             // 第1支路当前电流      30

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranCur2 = fTemp; 	             // 第2支路当前电流      32

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranCur3 = fTemp; 	             // 第3支路当前电流      34

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranCur4 = fTemp; 	             // 第4支路当前电流      36

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranState1 = usTemp16;            // 第1支路电池堆状态    38          0x1充满 0x2放空 0x3告警 0x4故障 0x0正常

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranState2 = usTemp16;            // 第2支路电池堆状态    39          0x1充满 0x2放空 0x3告警 0x4故障 0x0正常

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranState3 = usTemp16;            // 第3支路电池堆状态    40          0x1充满 0x2放空 0x3告警 0x4故障 0x0正常

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranState4 = usTemp16;            // 第4支路电池堆状态    41          0x1充满 0x2放空 0x3告警 0x4故障 0x0正常

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fSglTempCompVol = fTemp;			 // 单体电池温度补偿电压 42

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usStackStateFull = usTemp16;		 // 电池堆充满           44

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usStackStateEmpty = usTemp16;		 // 电池堆放空           45

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usStackStateTempAlarm = usTemp16;	 // 电池堆温度告警       46

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usStackStateCurAlarm = usTemp16;    // 电池堆电流告警       47

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usStackStateAllOff = usTemp16;		 // 电池堆接触器全断开   48

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usStackStateFault = usTemp16;		 // 电池堆保护(PCS故障)  49

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fStackSglChargeEQAdd = fTemp;      // 电池堆单次累计充电电量 50

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fStackSglDischargeEQAdd = fTemp; 	 // 电池堆单次累计放电电量 52

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranParalState5 = usTemp16; // 第5支路并联状态      54  1--闭合，2--断开

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranParalState6 = usTemp16; // 第6支路并联状态      55

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranParalState7 = usTemp16;  // 第7支路并联状态      56

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranParalState8 = usTemp16;  // 第8支路并联状态      57
		//
		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranSoc5 = fTemp;      // 第5支路电池SOC       58

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranSoc6 = fTemp;      // 第6支路电池SOC       60

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranSoc7 = fTemp;      // 第7支路电池SOC       62

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranSoc8 = fTemp;      // 第8支路电池SOC       64

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranCur5 = fTemp;      // 第5支路当前电流      66

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranCur6 = fTemp;      // 第6支路当前电流      68

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranCur7 = fTemp;      // 第7支路当前电流      70

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fBranCur8 = fTemp;      // 第8支路当前电流      72
		//
		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranState5 = usTemp16;          // 第5支路电池堆状态    74 

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranState6 = usTemp16;          // 第6支路电池堆状态    75  

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranState7 = usTemp16;           // 第7支路电池堆状态    76 

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usBranState8 = usTemp16;           // 第8支路电池堆状态    77 

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fStackMaxChargePower = fTemp;      // 电池堆最大充电功率   78 

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fStackMaxDischargePower = fTemp;   // 电池堆最大放电功率   80

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fStackMaxChargeCurrent = fTemp;    // 电池堆最大充电电流   82

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
		//pStack->fStackMaxDischargeCurrent = fTemp; // 电池堆最大放电电流   84

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usLinkageTripState = usTemp16;     // 联动跳机模式状态    86

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
		//pStack->usLinkageTripCtrl = usTemp16;      // 第8支路电池堆状态    87 

		iRetVal = 0;
	}	

	return iRetVal;
}
